Skip to main content
Workflows can be cancelled during execution to stop processing immediately and free up resources. This is particularly useful for long-running workflows, background tasks, or when user requirements change mid-execution. The cancellation system provides graceful termination with proper cleanup and event logging.

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 (using background=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

Developer Resources