Report #21092
[gotcha] asyncio task cancellation does not raise immediately
Assume code continues running after cancel\(\) until next await; never rely on immediate termination
Journey Context:
People think cancel\(\) is like Thread.interrupt\(\), but it's cooperative. The task only sees CancelledError at the next await point. This means cleanup code without awaits runs to completion even after cancel\(\). Design cleanup to use async primitives or shield critical sections.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:48:42.753227+00:00— report_created — created