dragon.workflows.batch.batch.Task

class Task[source]

Bases: object

__init__(task_core: TaskCore, batch: Batch, reads: list | None = None, writes: list | None = None, compiled: bool = False) None [source]

Initializes a new task.

Parameters:
  • task_core (TaskCore) – The core parts of the task, allowing us to send leaner objects to the managers.

  • batch (Batch) – The batch to which this task belongs.

  • reads (Optional[list ]) – A list of Read objects created by calling Batch.read().

  • writes (Optional[list ]) – A list of Write objects created by calling Batch.write().

  • compiled (bool ) – A flag indicating if this task is compiled.

Returns:

Returns None.

Return type:

None

Methods

__init__(task_core, batch[, reads, writes, ...])

Initializes a new 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.

log_paths()

Return the resolved stdout/stderr log file paths for this task.

Attributes

stderr_path

Return the resolved stderr log path for this task, if any.

stdout_path

Return the resolved stdout log path for this task, if any.

uid

Provides the unique ID for this task.

weight

Provides the HEFTY weight for this task.

__init__(task_core: TaskCore, batch: Batch, reads: list | None = None, writes: list | None = None, compiled: bool = False) None [source]

Initializes a new task.

Parameters:
  • task_core (TaskCore) – The core parts of the task, allowing us to send leaner objects to the managers.

  • batch (Batch) – The batch to which this task belongs.

  • reads (Optional[list ]) – A list of Read objects created by calling Batch.read().

  • writes (Optional[list ]) – A list of Write objects created by calling Batch.write().

  • compiled (bool ) – A flag indicating if this task is compiled.

Returns:

Returns None.

Return type:

None

get_manager_idx(block: bool = True, timeout: float = 1000000000.0) int [source]
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 with task_logs=True, task stdout and stderr are redirected to files; use Task.stdout_path(), Task.stderr_path(), Task.get_stdout(), Task.get_stderr(), or Task.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 explicit stdout/stderr path was given; otherwise they are forwarded to the client console like any other Dragon process. Task results remain in Batch’s internal results DDict until get() fetches them or Batch.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 calls Batch.join(), because that shutdown destroys the shared results DDict.

Parameters:
  • block (bool ) – If True (the default), block until the result is available or timeout is exceeded. If False, return immediately if the result is available, otherwise raise TaskNotReadyError.

  • timeout (float ) – The timeout for waiting. Defaults to 1e9. Ignored when block is False.

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

cancel(timeout: float = 1000000000.0) bool [source]

Best-effort cancellation request for this task.

Returns True when the scheduler accepted the cancellation and the task will complete with TaskCancelledError. Returns False when the task cannot be cancelled or already completed.

log_paths() dict [str , str | None ][source]

Return the resolved stdout/stderr log file paths for this task.

The returned dictionary contains stdout and stderr keys whose values are the shared-filesystem paths configured or generated for this task. A value is None when no path was configured, which happens for tasks submitted without an explicit stdout/stderr on a client created with task_logs=False (the default), since their output is forwarded to the client console instead of a file.

property stdout_path: str | None

Return the resolved stdout log path for this task, if any.

property stderr_path: str | None

Return the resolved stderr log path for this task, if any.

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, raises TaskNotReadyError if the task has not completed yet.

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, raises TaskNotReadyError if the task has not completed yet.

property uid

Provides the unique ID for this task.

property weight

Provides the HEFTY weight for this task.