<@ULVA73B9P> how to run 2 subflows in paralel
# ask-marvin
l
@Marvin how to run 2 subflows in paralel
m
To run two subflows in parallel using Prefect 3.x, you can utilize asynchronous execution. Prefect supports asynchronous functions and allows you to run flows concurrently using the standard async Python rules. Here's a concise way to achieve this: 1. Define your subflows: Decorate your Python functions with
@flow
to turn them into Prefect flows. 2. Use asyncio for parallel execution: Use Python's
asyncio
to run your subflows concurrently. Here's a simple example:
Copy code
python
from prefect import flow
import asyncio

@flow
async def subflow_one():
    # Your logic here
    return "Subflow One Completed"

@flow
async def subflow_two():
    # Your logic here
    return "Subflow Two Completed"

@flow
async def main_flow():
    # Run subflows in parallel
    results = await asyncio.gather(subflow_one(), subflow_two())
    print(results)

if __name__ == "__main__":
    main_flow()
### Key Points: - Asynchronous Execution: Use
async def
and
await
to enable parallel execution. - Task Runners: You can specify different task runners for nested flows to optimize execution. For more detailed information, you can refer to the Prefect documentation on writing flows and work pools. If you run into any issues, remember that Prefect 3.x has some changes from 2.x, such as the replacement of agents by workers and infra blocks by work pools.