Task
- class mosaic.core.task.Task(uid, sender_id, tessera, method, *args, **kwargs)[source]
Bases:
mosaic.core.base.RemoteBase
When we call a method on a remote tessera, two things will happen:
a Task will be generated on the remote tessera and queued to be executed by it;
and a TaskProxy is generated on the calling side as a pointer to that remote task.
We can use the task proxy to wait for the completion of the task (
await task_proxy
), as an argument to other tessera method calls, or to retrieve the result of the task (await task_proxy.result()
).It is also possible to access references to the individual outputs of the task by using
task_proxy.outputs
. Outputs can be accessed through their position:task_proxy.outputs[0]
will reference the first output of the task.A reference to the termination of the task is also available through
task_proxy.outputs.done
, which can be used to create explicit dependencies between tasks, thus controlling the order of execution.Tasks on a particular tessera are guaranteed to be executed in the order in which they were called, but no such guarantees exist for tasks on different tesserae.
A completed task is kept in memory at the worker for as long as there are proxy references to it. If none exist, it will be made available for garbage collection.
Objects of class Task should not be instantiated directly by the user.
- Parameters
uid (str) – UID of the task.
sender_id (str) – UID of the caller.
tessera (Tessera) – Tessera on which the task is to be executed.
method (callable) – Method associated with the task.
args (tuple, optional) – Arguments to pass to the method.
kwargs (optional) – Keyword arguments to pass to the method.
- check_result()[source]
Check if the result is present.
- Returns
str – State of the task.
Exception or None – Exception if task has failed, None otherwise.
- property collectable
Whether the object is ready for collection.
- get_result(key=None)[source]
Get task result.
- Parameters
key (optional) – Access particular item within the result, defaults to None.
- is_remote = True
- remote_runtime
Proxies that have references to this task.
- property sender_id
Caller UID.
- tessera_id
Tessera UID.
- type = 'task'
- class mosaic.core.task.TaskProxy(proxy, method, *args, **kwargs)[source]
Bases:
mosaic.core.base.ProxyBase
Proxy pointing to a remote task that has been or will be executed.
- property collectable
Whether the object is ready for collection.
- property done
Access to TaskDone of this task.
- property done_future
Future that will be completed when the remote task is done.
- property init_future
Future that will be completed when the remote task is initiated remotely.
- property outputs
Access individual outputs of the task.
- remote_runtime
Proxy to the runtime where the task lives.
- runtime_id
UID of the runtime where the task lives.
- set_exception(exc)[source]
Set exception during task execution.
- Parameters
exc (Exception description) –
- tessera_id
Tessera UID.
- type = 'task_proxy'
- class mosaic.core.task.TaskOutputGenerator(task_proxy)[source]
Bases:
object
Class that generates pointers to specific outputs of a remote task,