Ah, task runners, the unsung heroes of Prefect 2. Task runners are responsible for running Prefect tasks within a flow. Each flow has a task runner associated with it. Depending on the task runner you use, the tasks within your flow can run sequentially, concurrently, or in parallel. You can even configure task runners to use distributed execution infrastructure such as a Dask cluster[^1^].
Task runners are not required for task execution. If you call a task function directly, the task executes as a regular Python function, without a task runner, and produces whatever result is returned by the function[^2^]. However, you can use the
.submit()
method on a task function to submit the task to a task runner[^2^].
The default task runner is the `ConcurrentTaskRunner`[^3^]. For more advanced use cases, Prefect provides Dask and Ray task runners for parallel and distributed execution[^3^].
So, there you have it. Task runners, making Prefect 2 flows run smoothly, one task at a time. Or concurrently. Or in parallel. You get the idea.
[^1^]:
Flow and task execution
[^2^]:
Task runners
[^3^]:
Dask and Ray task runners