When to Use Cancellation
- User-initiated stops: Allow users to cancel long-running processes
- Resource management: Free up computational resources when workflows are no longer needed
- Priority changes: Cancel lower-priority workflows to make room for urgent tasks
Cancelling Background Workflows
For workflows running in the background (usingbackground=True), you can cancel them using the run_id:
Example
When a workflow in streaming mode is cancelled, a specific event is triggered:
WorkflowRunEvent.workflow_cancelled or simply known as WorkflowCancelledEvent