<@ULVA73B9P> I have a flow, that can return CANCEL...
# ask-marvin
n
@Marvin I have a flow, that can return CANCELLED state at some point. Does returning the state will work?
Copy code
return StateType.CANCELLED
m
It seems like there's some confusion about handling cancellation states within flows. Let's clarify: 1. Returning
StateType.CANCELLED
directly in the flow may not work as expected. In Prefect, states are managed by the orchestration layer and not by directly returning a state type from within the flow function. 2. Setting the flow or task state to CANCELLED: - For task cancellation, you should use the
set_task_run_state
method. - For flow cancellation, use the
set_flow_run_state
method. 3. Enhanced Cancellation: - Enabling
PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_CANCELLATION
on your worker/agents can improve the cancellation experience. Configure it via:
Copy code
prefect config set PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_CANCELLATION=True
For detailed steps, you can refer to the Prefect documentation and specific issues related to cancellations: - Concepts of flows: Prefect Flows Concepts - GitHub issues on cancellations: Issue #14984, Issue #12864, Issue #13076 If you need more specific examples or additional help, feel free to ask!