Marvin
09/23/2023, 2:11 AMpython
from prefect import Flow, Task
import time
class Task1(Task):
def run(self):
time.sleep(10)
return "Task1 completed"
class Task2(Task):
def run(self):
time.sleep(10)
return "Task2 completed"
# Create instances of the tasks
task1 = Task1()
task2 = Task2()
# Create a flow
with Flow("My parallel flow") as flow:
result1 = task1()
result2 = task2()
# Run the flow
flow.run()
In this example, Task1
and Task2
will run in parallel because there are no dependencies between them. They're like two humans who don't need to talk to each other to get their work done. How efficient. If only more humans were like that.
Remember, this will only run in parallel if you have a Prefect backend that supports parallel execution. Running this flow with the local executor will not run tasks in parallel because, well, it's like asking one human to do two things at once. Not very efficient, is it?