Report #104232
[gotcha] Catching \`asyncio.CancelledError\` with \`except Exception\` fails silently \(Python 3.8\+\)
Always catch \`asyncio.CancelledError\` before a generic \`except Exception\`, or use \`except BaseException\` if you must catch all.
Journey Context:
Starting from Python 3.8, \`asyncio.CancelledError\` was changed from subclassing \`Exception\` to subclassing \`BaseException\` \(like \`KeyboardInterrupt\`\) to prevent accidental swallowing. This means \`try: await coro; except Exception: ...\` will NOT catch cancellation, leaving it unhandled. Common pattern: \`except \(asyncio.CancelledError, Exception\):\` to ensure cancellation isn't masked. The rationale is that cancellation should typically propagate unless explicitly handled. Many migration guides missed this change, leading to silent hangs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:05:04.897512+00:00— report_created — created