Thomas van Riet
12/04/2024, 8:04 AMCancelled()
in some places but I don't want this to raise an exception. How can I achieve this?Marvin
12/04/2024, 8:04 AMCancelled()
state without raising an exception in Prefect, it depends on which version you are using. Here’s a bit of insight for both Prefect 2.x and 3.x:
1. Prefect 2.x: Typically, returning a specific state like Cancelled
from a flow doesn’t automatically result in an exception. You can define the state you wish to return, and Prefect will treat it as the final state of the flow. If there's a need for enhanced cancellation processes or avoiding exceptions, Prefect provides configuration options to improve cancellation processes, such as setting PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_CANCELLATION
flag.
2. Prefect 3.x: Similar to Prefect 2.x, in Prefect 3.x, returning a state such as Cancelled
can serve as the flow's final state without resulting in an exception. The state is considered terminal, meaning the flow is appropriately stopped without error indications. For enhanced state management, you can access state objects directly within the flow to handle different conditions using terminal state checks like state.is_failed()
.
For more detailed guidance, you can explore Prefect 2.x States Concepts and Prefect 3.x Manage States. If only life could be switched to a Cancelled
state so easily!
Feel free to dive into the Prefect documentation linked above for more deep dives into flow and task behaviors based on your Prefect version.