dragon.workflows.batch.batch.Function
- class Function[source]
Bases:
Task- __init__(batch, target: Callable , args: tuple = (), kwargs: dict = {}, reads: list | None = None, writes: list | None = None, name: str | None = None, timeout: float = 1000000000.0) None [source]
Creates a new function task. Arguments for the function that are of type
AsyncDictwill create a dependency for this task on the output specified by theAsyncDict. Further, the output specified by theAsyncDictwill be passed in place of theAsyncDictwhen the function executes.- Parameters:
batch – The batch in which this function task will execute.
func – The function to associate with the object.
*args –
The arguments for the function.
reads (Optional[list ]) – A list of
Readobjects created by callingBatch.read.writes (Optional[list ]) – A list of
Writeobjects created by callingBatch.write.name (Optional[str ]) – A human-readable name for the task.
- Returns:
Returns None.
- Return type:
None
Methods
__init__(batch, target[, args, kwargs, ...])Creates a new function task.
dump_dag(file_name)Dump a PNG image of the dependency DAG associated with a compiled program.
get()Performs a batch fence to guarantee the completion of all tasks batched in the background, and then gets the result for this task.
read(obj, *channels)Indicates READ accesses of a specified set of channels on a communication object, and associates these accesses with this task.
run([timeout])Starts a task and waits for it to complete.
start()Start this task by sending its work chunks to the managers.
wait([timeout])Wait for this Task to complete.
write(obj, *channels)Indicates WRITE accesses of a specified set of channels on a communication object, and associates these accesses with this task.
Attributes
Handle for the task's result.
Handle for the task's stderr.
Handle for the task's stdout.
Provides the unique ID for this task.
- __init__(batch, target: Callable , args: tuple = (), kwargs: dict = {}, reads: list | None = None, writes: list | None = None, name: str | None = None, timeout: float = 1000000000.0) None [source]
Creates a new function task. Arguments for the function that are of type
AsyncDictwill create a dependency for this task on the output specified by theAsyncDict. Further, the output specified by theAsyncDictwill be passed in place of theAsyncDictwhen the function executes.- Parameters:
batch – The batch in which this function task will execute.
func – The function to associate with the object.
*args –
The arguments for the function.
reads (Optional[list ]) – A list of
Readobjects created by callingBatch.read.writes (Optional[list ]) – A list of
Writeobjects created by callingBatch.write.name (Optional[str ]) – A human-readable name for the task.
- Returns:
Returns None.
- Return type:
None
- dump_dag(file_name: str ) None [source]
Dump a PNG image of the dependency DAG associated with a compiled program.
- Parameters:
file_name – Name for the new PNG file.
- Returns:
Returns None.
- Return type:
None
- get()[source]
Performs a batch fence to guarantee the completion of all tasks batched in the background, and then gets the result for this task.
- Returns:
Returns the result of this task.
- Return type:
Any
- read(obj, *channels) None [source]
Indicates READ accesses of a specified set of channels on a communication object, and associates these accesses with this task. Associating READ accesses with a task allows the Batch service to infer dependencies between subtasks in a compiled task, but has no effect on individual (non-compiled) tasks.
- Parameters:
obj – The communication object being accessed.
*channels –
A tuple of channels on the communcation object that will be read from.
- Returns:
Returns None.
- Return type:
None
- property result
Handle for the task’s result. This should not be accessed until the task is started.
resultonly applies to individual tasks and compiled tasks with a single subtask. The handle has type AsyncDict.
- run(timeout: float = 1000000000.0) Any [source]
Starts a task and waits for it to complete. Currently, a task can only be started once and cannot be restarted after it completes.
- Parameters:
timeout (float ) – The timeout for waiting. Defaults to 1e9.
- Raises:
TimeoutError – If the specified timeout is exceeded.
Exception – If this Task raised an exception while running. The exception raised by the task is propagated back to the host that started the task so it can be raised here.
- Returns:
Returns the result of the operation being waited on.
- Return type:
Any
- start() None [source]
Start this task by sending its work chunks to the managers. Currently, a task can only be started once and cannot be restarted after it completes. If a task is a subtask of a compiled task, then
startmust be called for the compiled task and not the subtask.- Returns:
Returns None.
- Return type:
None
- property stderr
Handle for the task’s stderr. This should not be accessed until the task is started.
stderronly applies to individual tasks and compiled tasks with a single subtask. The handle has type AsyncDict.
- property stdout
Handle for the task’s stdout. This should not be accessed until the task is started.
stdoutonly applies to individual tasks and compiled tasks with a single subtask. The handle has type AsyncDict.
- property uid
Provides the unique ID for this task.
- wait(timeout: float = 1000000000.0) None [source]
Wait for this Task to complete. This can only be called after
starthas been called. This function does not return the task’s result; instead, usegetfor that purpose.- Parameters:
timeout – The timeout for waiting. Defaults to 1e9.
- Raises:
TimeoutError – If the specified timeout is exceeded.
- Returns:
Returns None.
- Return type:
None
- write(obj, *channels) None [source]
Indicates WRITE accesses of a specified set of channels on a communication object, and associates these accesses with this task. Associating WRITE accesses with a task allows the Batch service to infer dependencies between subtasks in a compiled task, but has no effect on individual (non-compiled) tasks.
- Parameters:
obj – The communication object being accessed.
*channels –
A tuple of channels on the communcation object that will be written to.
- Returns:
Returns None.
- Return type:
None