Task

class mosaic.core.task.Task(uid, sender_id, tessera, method, *args, **kwargs)[source]

Bases: 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.

add_event(event_name, **kwargs)[source]
add_profile(profile, **kwargs)[source]
args_value()[source]

Processed value of the args of the task.

Return type:

tuple

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.

is_remote = True
kwargs_value()[source]

Processed value of the args of the task.

Return type:

dict

async prepare_args()[source]

Prepare the arguments of the task for execution.

Return type:

Future

classmethod remote_cls()[source]

Class of the remote.

remote_runtime

Proxies that have references to this task.

property sender_id

Caller UID.

async set_done()[source]

Set task as done.

async set_exception(exc)[source]

Set task exception

Parameters:

exc (Exception) –

async set_result(result)[source]

Set task result.

Parameters:

result

tessera_id

Tessera UID.

type = 'task'
class mosaic.core.task.TaskProxy(proxy, method, *args, **kwargs)[source]

Bases: ProxyBase

Proxy pointing to a remote task that has been or will be executed.

add_done_callback(fun)[source]

Add done callback.

Parameters:

fun (callable) –

add_event(event_name, **kwargs)[source]
add_profile(profile, **kwargs)[source]
async check_result()[source]

Check the remote result.

property collectable

Whether the object is ready for collection.

deregister_runtime(uid)[source]
property done

Access to TaskDone of this task.

property done_future

Future that will be completed when the remote task is done.

async init()[source]

Asynchronous correlate of __init__.

property init_future

Future that will be completed when the remote task is initiated remotely.

property outputs

Access individual outputs of the task.

classmethod remote_cls()[source]

Class of the remote.

remote_runtime

Proxy to the runtime where the task lives.

async result()[source]

Gather remote result from the task.

Return type:

Task result

runtime_id

UID of the runtime where the task lives.

set_done()[source]

Set task as done.

set_exception(exc)[source]

Set exception during task execution.

Parameters:

exc (Exception description) –

set_result(result)[source]

Set task result.

Parameters:

result

async size(pending=False)[source]

Size of the task result in bytes.

tessera_id

Tessera UID.

type = 'task_proxy'
wait()[source]

Wait on the task to be completed.

class mosaic.core.task.TaskOutputGenerator(task_proxy)[source]

Bases: object

Class that generates pointers to specific outputs of a remote task,

class mosaic.core.task.TaskOutput(key, task_proxy)[source]

Bases: TaskOutputBase

Pointer to specific remote output of a class.

async result()[source]

Gather output from the remote task.

Return type:

Output

async size(pending=False)[source]

Size of the task result in bytes.

class mosaic.core.task.TaskDone(task_proxy)[source]

Bases: TaskOutputBase

Reference to the termination of a remote task.

async result()[source]

Wait for task termination.

async size(pending=False)[source]