Romain Vincent
02/05/2025, 9:52 AMMarvin
02/05/2025, 9:52 AMThreadPoolTaskRunner
, DaskTaskRunner
, and RayTaskRunner
, which can be used for concurrent, parallel, or distributed task execution.
Here's a simple example of how you might define a task runner for a flow:
python
from prefect import flow
from prefect.task_runners import ThreadPoolTaskRunner
@flow(task_runner=ThreadPoolTaskRunner())
def my_flow():
# Define your tasks here
pass
In this example, ThreadPoolTaskRunner
is used to run tasks concurrently within a thread pool. You can replace it with other task runners like DaskTaskRunner
or RayTaskRunner
based on your requirements.
For more information, you can refer to the Prefect Task Runners documentation.
If you have any specific requirements or need further assistance, feel free to ask!Romain Vincent
02/05/2025, 9:53 AMMarvin
02/05/2025, 9:53 AMpython
from prefect import flow
from prefect.task_runners import ThreadPoolTaskRunner, DaskTaskRunner
@flow(task_runner=ThreadPoolTaskRunner())
def main_flow():
# This flow uses ThreadPoolTaskRunner by default
# Call a nested flow with a different task runner
nested_dask_flow()
@flow(task_runner=DaskTaskRunner())
def nested_dask_flow():
# This flow uses DaskTaskRunner
# Define tasks that benefit from parallel execution
pass
if __name__ == "__main__":
main_flow()
In this setup, main_flow
uses ThreadPoolTaskRunner
, while nested_dask_flow
uses DaskTaskRunner
. This allows you to execute different parts of your workflow with different task runners, effectively adapting to runtime needs.
For more details, you can refer to the Prefect Task Runners documentation.Romain Vincent
02/05/2025, 9:57 AMMarvin
02/05/2025, 9:57 AM