flytekit.extend.Promise#
- class flytekit.extend.Promise(var, val, type=None)[source]#
This object is a wrapper and exists for three main reasons. Let’s assume we’re dealing with a task like
@task def t1() -> (int, str): ...
Handling the duality between compilation and local execution - when the task function is run in a local execution mode inside a workflow function, a Python integer and string are produced. When the task is being compiled as part of the workflow, the task call creates a Node instead, and the task returns two Promise objects that point to that Node.
One needs to be able to call
x = t1().with_overrides(...)
If the task returns an integer or a
(int, str)
tuple liket1
above, callingwith_overrides
on the result would throw an error. This Promise object adds that.Assorted handling for conditionals.
Methods
- Parameters:
var (str)
val (Union[NodeOutput, _literals_models.Literal])
type (Optional[_type_models.LiteralType])
- with_overrides(node_name=None, aliases=None, requests=None, limits=None, timeout=<object object>, retries=None, interruptible=None, name=None, task_config=None, container_image=None, accelerator=None, cache=None, cache_version=None, cache_serialize=None, *args, **kwargs)[source]#
- Parameters:
node_name (str | None)
requests (Resources | None)
limits (Resources | None)
retries (int | None)
interruptible (bool | None)
name (str | None)
task_config (Any | None)
container_image (str | None)
accelerator (BaseAccelerator | None)
cache (bool | None)
cache_version (str | None)
cache_serialize (bool | None)
Attributes
- attr_path
The attribute path the promise will be resolved with. :rtype: List[Union[str, int]]
- is_ready
Returns if the Promise is READY (is not a reference and the val is actually ready)
Usage
p = Promise(...) ... if p.is_ready(): print(p.val) else: print(p.ref)
- ref
If the promise is NOT READY / Incomplete, then it maps to the origin node that owns the promise
- val
If the promise is ready then this holds the actual evaluate value in Flyte’s type system
- var
Name of the variable bound with this promise