<@ULVA73B9P> can multiple workers run subflows in ...
# ask-marvin
i
@Marvin can multiple workers run subflows in the same flow?
m
thought for 41.0 seconds
Yes, multiple workers can run subflows from the same parent flow, but there's an important distinction to understand: 1. Default Behavior: By default, subflows run in the same process as their parent flow. This means they execute on the same worker that's running the parent flow. 2. Distributed Execution: If you want subflows to run on different workers, you'll need to create separate deployments for them and call them using
flow.from_source()
. This gives you the flexibility to: - Run subflows on different infrastructure - Use different work pools for different parts of your workflow - Scale execution across multiple machines Here's a simple example of how you might set this up:
Copy code
python
from prefect import flow

@flow
def subflow(x):
    return x + 1

@flow
def parent_flow():
    # This runs in the same process
    result1 = subflow(1)
    
    # This can run on a different worker
    deployment_flow = flow.from_source(
        source="<https://github.com/your-repo>",
        entrypoint="flows.py:subflow"
    )
    result2 = deployment_flow(2)
The links to the documentation provide more details about workers and workflow patterns if you'd like to dive deeper into distributed execution configurations.