<@ULVA73B9P> how to fire-and-forget a flow (a deployment is ok) meaning trigger an independant flow ...
e
@Marvin how to fire-and-forget a flow (a deployment is ok) meaning trigger an independant flow and don’t wait for the results.
m
thought for 113.6 seconds
In Prefect 3.x, the simplest fire-and-forget pattern is to trigger a deployment with
timeout=0
.
Copy code
python
from prefect import flow
from prefect.deployments import run_deployment

@flow
def parent_flow():
    flow_run = run_deployment(
        name="child-flow/my-deployment",
        parameters={"x": 1},
        timeout=0,
    )

    print(f"Triggered child flow run: {flow_run.id}")
    print("Continuing immediately...")
What this does - Starts an independent flow run from a deployment - Returns immediately - Does not wait for completion - Gives you a
FlowRun
object back, so you can keep the run ID if you want to inspect it later Important note -
run_deployment()
does require a deployment - A worker must be running for that deployment’s work pool If you call a flow directly like this:
Copy code
python
child_flow()
that is not fire-and-forget — it behaves like a nested subflow and the parent waits for it. If you want the child to appear as related to the parent in the UI,
run_deployment()
does that by default when called from inside a flow. If you want it completely detached, you can set:
Copy code
python
run_deployment(
    name="child-flow/my-deployment",
    timeout=0,
    as_subflow=False,
)
Recommendation - Use direct flow calls for true subflows when you want to wait - Use
run_deployment(..., timeout=0)
when you want background / independent execution Relevant docs: - Run deployments - Deployments If you want, I can also show: 1. how to deploy the child flow, or 2. how to trigger it asynchronously from async code