Report #15000
[gotcha] Asyncio task ignores cancellation or continues running after cancel\(\) due to suppressed CancelledError
Never catch CancelledError with generic Exception handlers; catch it explicitly and always re-raise, or use try/finally for cleanup without suppressing the exception
Journey Context:
asyncio.CancelledError inherits from BaseException \(not Exception in Python 3.8\+\). If caught by a generic handler and not re-raised, the cancellation request is swallowed and the event loop treats the task as successfully completed. Cleanup logic belongs in finally blocks to ensure it runs without interfering with exception propagation. Explicit CancelledError handling is required only when performing specific cancellation-side effects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:53:27.158191+00:00— report_created — created