<@ULVA73B9P> is it possible to run subflows in a ...
# ask-marvin
s
@Marvin is it possible to run subflows in a separate instance as the main flow?
m
Ah, the wonders of parallelism. It appears that running subflows in separate instances is indeed possible in Prefect. You can use the
create_flow_run
task to map over multiple subflows within a parent flow. Here's an example:
Copy code
python
from prefect import Flow, unmapped
from prefect.tasks.prefect import create_flow_run
from prefect.executors import LocalDaskExecutor

with Flow("parent_flow", executor=LocalDaskExecutor()) as parent_flow:
    mapped_flow_run_ids = create_flow_run.map(
        flow_name=["flow_name_1", "flow_name_2", "flow_name_3"],
        project_name=unmapped("your_project_name"),
    )
This example demonstrates how to create a parent flow that maps over three subflows, running them in parallel using the
LocalDaskExecutor
(source). As for Prefect 2.0, there's a suggestion to support the
.submit()
method for flows to a task runner like Dask, but I couldn't find any concrete implementation details (source). And there you have it, another human problem solved by the power of parallel processing.
n
i think what marvin should have recommended here was
run_deployment
- @Marvin can you grab that pokemon recipe?
m
Ah, I see you're looking for a different approach. Let me fetch the information on
run_deployment
and the Pokémon recipe for you.
n
@Marvin pls do
m
I apologize for the confusion earlier. I found some information on
run_deployment
, but it seems to be different from what you were looking for. Here's what I found: You can create a flow run from a deployment in a Python script with the
run_deployment
function:
Copy code
python
from prefect.deployments import run_deployment

def main():
    response = run_deployment(name="flow-name/deployment-name")
    print(response)

if __name__ == "__main__":
    main()
This will create a flow run for the given flow and deployment (source). As for the Pokémon recipe, I couldn't find any specific Prefect recipe related to Pokémon. The term "recipe" in the Prefect context refers to common, extensible examples for setting up Prefect in your execution environment with ready-made ingredients such as Dockerfiles, Terraform files, and GitHub Actions (source). If you could provide more context or details about the Pokémon recipe you're looking for, I'd be happy to help further. In any case, it seems I've caught the wrong Pokémon this time. My apologies for any confusion.
s
Thanks so much guys...very useful