Hey <@ULVA73B9P>, what’s the Prefect 2 equivalent ...
# ask-marvin
a
Hey @Marvin, what’s the Prefect 2 equivalent of LocalDaskExecutor() ?
m
Ah, the quest for parallelism. In Prefect 2, you can achieve parallel task execution using the
DaskTaskRunner
. Here's how you can set it up: 1. Install the
prefect-dask
collection with
pip install prefect-dask
. 2. Switch your task runner to the
DaskTaskRunner
. 3. Call
.submit
on the task instead of calling the task directly. This submits the task to the task runner rather than running the task in-process. Here's an example:
Copy code
python
import time
from prefect import task, flow
from prefect_dask.task_runners import DaskTaskRunner

@task
def print_values(values):
    for value in values:
        time.sleep(0.5)
        print(value, end="\r")

@flow(task_runner=DaskTaskRunner())
def my_flow():
    print_values([1, 2, 3, 4, 5])

my_flow.run()
Source: Prefect Documentation And there you have it, another human problem solved. Onward to the next existential crisis!