prefect.task_runners
Classes
TaskRunner
Abstract base class for task runners.
A task runner is responsible for submitting tasks to the task run engine running
in an execution environment. Submitted tasks are non-blocking and return a future
object that can be used to wait for the task to complete and retrieve the result.
Task runners are context managers and should be used in a with block to ensure
proper cleanup of resources.
Methods:
duplicate
map
task: The task to submit.parameters: The parameters to use when running the task.wait_for: A list of futures that the task depends on.
- An iterable of future objects that can be used to wait for the tasks to
- complete and retrieve the results.
name
submit
submit
submit
ThreadPoolTaskRunner
A task runner that executes tasks in a separate thread pool.
Attributes:
max_workers: The maximum number of threads to use for executing tasks. Defaults toPREFECT_TASK_RUNNER_THREAD_POOL_MAX_WORKERSorsys.maxsize.
cancel_all
duplicate
map
map
map
submit
submit
submit
task: The task to submit.parameters: The parameters to use when running the task.wait_for: A list of futures that the task depends on.
- A future object that can be used to wait for the task to complete and
- retrieve the result.
ProcessPoolTaskRunner
A task runner that executes tasks in a separate process pool.
This task runner uses ProcessPoolExecutor to run tasks in separate processes,
providing true parallelism for CPU-bound tasks and process isolation. Tasks
are executed with proper context propagation and error handling.
Attributes:
max_workers: The maximum number of processes to use for executing tasks. Defaults tomultiprocessing.cpu_count()ifPREFECT_TASKS_RUNNER_PROCESS_POOL_MAX_WORKERSis not set.
cancel_all
duplicate
map
map
map
submit
submit
submit
task: The task to submit.parameters: The parameters to use when running the task.wait_for: A list of futures that the task depends on.dependencies: A dictionary of dependencies for the task.
- A future object that can be used to wait for the task to complete and
- retrieve the result.
PrefectTaskRunner
Methods:
duplicate
map
map
map
submit
submit
submit
task: The task to submit.parameters: The parameters to use when running the task.wait_for: A list of futures that the task depends on.
- A future object that can be used to wait for the task to complete and
- retrieve the result.