Report #29873
[gotcha] asyncio.CancelledError not caught by except Exception after Python 3.8
Catch asyncio.CancelledError explicitly before Exception, or use try/finally for cleanup without suppressing. Never use bare except: or except Exception: to handle task cancellation.
Journey Context:
In Python 3.7 and earlier, asyncio.CancelledError inherited from Exception, so generic handlers caught it. In 3.8\+, it inherits from BaseException to prevent accidental suppression during cleanup. Legacy patterns like 'except Exception: cleanup\(\); raise' now miss cancellation, leaving tasks in limbo. The fix prioritizes explicit cancellation handling, ensuring cleanup runs while allowing the cancellation to propagate.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:31:57.209735+00:00— report_created — created