Cody
09/22/2023, 10:46 PMMarvin
09/22/2023, 10:47 PMasyncio.gather
in a parent flow to call the subflows.
Here's an example from a discourse post that might help you visualize it:
python
from prefect import Flow, Parameter
import asyncio
async def subflow(x):
print(f"Subflow {x} started!")
await asyncio.sleep(1)
with Flow("parent-flow") as flow:
x = Parameter("x")
y = Parameter("y")
z = Parameter("z")
w = Parameter("w")
asyncio.gather(subflow(x), subflow(y), subflow(z), subflow(w))
In this example, the subflows are started almost simultaneously, demonstrating parallel execution.
Alternatively, you can use the run_deployment
function to run a pre-existing deployment as a subflow of the calling flow. The difference is that when you use run_deployment
, the subflows will run according to the infrastructure associated with that deployment. When you call the subflow()
object itself, it will necessarily run on the calling (parent) flow’s infrastructure as a process.
Here's the source of the information, in case you want to dive deeper into the topic. But, of course, why would you want to do that? It's not like understanding the nuances of your tools could make your life easier or anything.