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, stdout: str | Path | None = None, stderr: str | Path | None = None) None [source]
Creates a new function task. Arguments for the function that are of type
Taskwill create a dependency for this task on the output of the task specified by the argument. Further, the output of the specified task will be passed in place of theTaskargument when 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.
cancel([timeout])Best-effort cancellation request for this task.
get([block, timeout])Wait for this Task to complete and return its result.
get_manager_idx([block, timeout])get_stderr([block, timeout, encoding])Read this task's stderr log.
get_stdout([block, timeout, encoding])Read this task's stdout log.
Return the resolved stdout/stderr log file paths for this task.
Attributes
Return the resolved stderr log path for this task, if any.
Return the resolved stdout log path for this task, if any.
Provides the unique ID for this task.
Provides the HEFTY weight 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, stdout: str | Path | None = None, stderr: str | Path | None = None) None [source]
Creates a new function task. Arguments for the function that are of type
Taskwill create a dependency for this task on the output of the task specified by the argument. Further, the output of the specified task will be passed in place of theTaskargument when 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
- cancel(timeout: float = 1000000000.0) bool [source]
Best-effort cancellation request for this task.
Returns
Truewhen the scheduler accepted the cancellation and the task will complete withTaskCancelledError. ReturnsFalsewhen the task cannot be cancelled or already completed.
- get(block: bool = True, timeout: float = 1000000000.0) None [source]
Wait for this Task to complete and return its result.
get()never prints task stdout or stderr. When the owning Batch was created withtask_logs=True, task stdout and stderr are redirected to files; useTask.stdout_path(),Task.stderr_path(),Task.get_stdout(),Task.get_stderr(), orTask.log_paths()to inspect the resolved task logs. When task logging is disabled (the default), task stdout and stderr are not captured to files unless an explicitstdout/stderrpath was given; otherwise they are forwarded to the client console like any other Dragon process. Task results remain in Batch’s internal results DDict untilget()fetches them orBatch.clear_results()discards them. Once fetched here, the result is cached on this client-side task handle for subsequent calls. In unmanaged mode, fetch any result you need before the last client callsBatch.join(), because that shutdown destroys the shared results DDict.- Parameters:
- Raises:
TimeoutError – If the specified timeout is exceeded.
:raises
TaskNotReadyError: If block is False and the result is not yet available.- Returns:
Returns the result of the task.
- Return type:
Any
- get_stderr(block: bool = True, timeout: float = 1000000000.0, encoding: str = 'utf-8') str | None [source]
Read this task’s stderr log.
By default, waits for the task to complete before reading the final log file. When block is
False, raisesTaskNotReadyErrorif the task has not completed yet.
- get_stdout(block: bool = True, timeout: float = 1000000000.0, encoding: str = 'utf-8') str | None [source]
Read this task’s stdout log.
By default, waits for the task to complete before reading the final log file. When block is
False, raisesTaskNotReadyErrorif the task has not completed yet.
- log_paths() dict [str , str | None ][source]
Return the resolved stdout/stderr log file paths for this task.
The returned dictionary contains
stdoutandstderrkeys whose values are the shared-filesystem paths configured or generated for this task. A value isNonewhen no path was configured, which happens for tasks submitted without an explicitstdout/stderron a client created withtask_logs=False(the default), since their output is forwarded to the client console instead of a file.
- property uid
Provides the unique ID for this task.
- property weight
Provides the HEFTY weight for this task.