Skip to main content
Run a workflow in a background thread, then cancel it mid-run with Workflow.cancel_run(run_id). The example covers:
  1. Thread-based Execution: Running workflows in separate threads for non-blocking operation
  2. Dynamic Cancellation: Cancelling workflows while they’re actively running
  3. Cancellation Events: Handling and responding to cancellation events
  4. Status Tracking: Monitoring workflow status throughout execution and cancellation
workflow_cancellation.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

4

Run the example

Save the code above as workflow_cancellation.py, then run: