infrastructure_pid or infrastructure identifier.
Generally, this is composed of two parts:
- Scope: identifying where the infrastructure is running.
- ID: a unique identifier for the infrastructure within the scope.
- Processes: The machine hostname and the PID.
- Docker Containers: The Docker API URL and container ID.
- Kubernetes Jobs: The Kubernetes cluster name and the job name.
- If the infrastructure for the flow run does not support cancellation, cancellation will not work.
- If the identifier scope does not match when attempting to cancel a flow run, the worker cannot cancel the flow run. Another worker may attempt cancellation.
- If the infrastructure associated with the run cannot be found or has already been killed, the worker marks the flow run as cancelled.
- If the
infrastructre_pidis missing, the flow run is marked as cancelled but cancellation cannot be enforced. - If the worker runs into an unexpected error during cancellation, the flow run may or may not be cancelled depending on where the error occurred. The worker will try again to cancel the flow run. Another worker may attempt cancellation.
If a flow run remains in
CANCELLING for longer than the cancelling timeout (default: 300 seconds), the server automatically transitions it to CANCELLED.
This acts as a safety net when a worker is unavailable or fails to complete the cancellation process.
To adjust the timeout, set PREFECT_SERVER_SERVICES_CANCELLATION_CLEANUP_CANCELLING_TIMEOUT_SECONDS to the desired number of seconds.Cancel through the CLI
From the command line in your execution environment, you can cancel a flow run by using theprefect flow-run cancel CLI command, passing the ID of the flow run.
Cancel through the UI
Navigate to the flow run’s detail page and clickCancel in the upper right corner.

Cancel through the Python client
To request cancellation programmatically, set the flow run state toCANCELLING.
This is the same state used by the CLI, UI, and automation cancellation actions.
Cancel through the REST API
To request cancellation with the REST API, set the flow run state toCANCELLING.