<@ULVA73B9P> i have a parent flow and sub flow, pa...
# ask-marvin
m
@Marvin i have a parent flow and sub flow, parent flow has crashed due to not enough ram/cpu. but sub flow in run state, i want stop that but UI doenst allow me to cancle. how to cancle it
âś… 1
🙌 1
m
âś… thought for 133.8 seconds
Got it — when the parent crashes, the UI can sometimes be stubborn about cancelling the child. You can cancel the subflow directly via the CLI. 1) Find the subflow run ID (filter to RUNNING):
Copy code
prefect flow-run ls --state RUNNING --limit 50
2) Cancel it by ID:
Copy code
prefect flow-run cancel <flow-run-id>
If the state flips to CANCELLING but the run doesn’t actually stop, the process/container may not be responding to the cancellation signal. Since you’re using an ECS EC2 work pool, you can force-stop the underlying ECS task (this will end the flow run): - AWS Console: find the task for that flow run in your cluster and Stop it - Or via AWS CLI:
Copy code
aws ecs stop-task --cluster <cluster-name> --task <task-arn>
If you want, share the subflow run ID (or its URL) and I can help double-check the state and confirm the right target to stop.
m
@Marvin currently i am running subflow as usual function call. how to run it as a flow run so the flow run in seperate ecs task other than parent
m
âś… thought for 331.6 seconds
You’ll want to turn that “subflow” into its own deployment, then trigger it from the parent with
run_deployment
. That will enqueue a separate flow run on your ECS EC2 work pool, so it runs in its own ECS task/container and can be cancelled independently. High-level steps: 1) Create a deployment for the child flow - Put the child flow in its own file, e.g.
child.py
with
@flow def child_flow(...): ...
- From your project root, run
prefect deploy
and select the child entrypoint (
./child.py:child_flow
), your ECS work pool, and work queue. - Note: In Prefect 3.x, this replaces the old 2.x “deployment build” flow. 2) Call the child deployment from the parent using run_deployment - This triggers the child deployment as a separate flow run (and separate ECS task). Use
as_subflow=True
to link it in the UI as a subflow of the parent. Async parent flow example:
Copy code
from prefect import flow
from prefect.deployments import run_deployment

@flow
async def parent_flow():
    # Optional: small POC resources; bump later for prod
    ecs_job_vars = {
        "cpu": "512",
        "memory": "1024",
        "env": {
            # if you use Prefect Variables/Blocks for DB creds, load them in the child
            "PREFECT_LOGGING_LEVEL": "INFO",
        },
    }

    # Trigger the child deployment as its own flow run in ECS
    child_run = await run_deployment(
        name="child-flow/child-deployment",  # flow-name/deployment-name
        parameters={"some_param": "value"},
        as_subflow=True,                      # links to parent in UI
        timeout=0,                            # return immediately; parent continues
        job_variables=ecs_job_vars,           # ECS overrides for this run
        # work_queue_name="your-queue",       # optional override
    )

    return child_run
Sync parent flow example (blocks until the child finishes unless you set
timeout=0
):
Copy code
from prefect import flow
from prefect.deployments import run_deployment

@flow
def parent_flow():
    child_run = run_deployment(
        name="child-flow/child-deployment",
        as_subflow=True,
        timeout=0,  # return immediately; omit or set >0 to wait
        job_variables={"cpu": "512", "memory": "1024"},
    )
    return child_run
Notes: -
as_subflow=True
links the child to the parent in the UI. If you’d rather it run completely independent of the parent (no link), set
as_subflow=False
. -
timeout=None
(default) waits until the child finishes.
timeout=0
returns immediately and the child continues in ECS. -
job_variables
lets you override ECS resources per run (e.g.,
cpu
,
memory
,
env
,
image
, IAM roles if needed). These merge with your deployment’s defaults. For your POC, start small (e.g., 512 CPU / 1024 MB). For prod, you mentioned ~8GB (
"memory": "8192"
). Once you do this, the child run is a first-class flow run with its own ECS task, so you can cancel it from the UI or via CLI:
Copy code
prefect flow-run cancel <child-flow-run-id>
If you’d like, share your child flow’s entrypoint and I can suggest a minimal
prefect deploy
setup for your ECS EC2 pool.