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.
Examples:
Use a thread pool task runner with a flow:
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.
Examples:
Use a process pool task runner with a flow:
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.