Report #16543
[gotcha] Catching CancelledError in try/except without re-raising leaves asyncio task in partially cancelled limbo
Always re-raise \`CancelledError\` after cleanup in \`except CancelledError\` blocks, or use \`finally\` for cleanup instead; use \`except Exception\` rather than bare \`except\` to avoid catching BaseException subclasses
Journey Context:
When \`Task.cancel\(\)\` is called, the event loop raises \`CancelledError\` \(a \`BaseException\`, not \`Exception\`\) at the next await point. If the exception is caught and suppressed without re-raising, the task never completes the cancellation protocol, leaving it in a 'cancelling' state indefinitely. This causes hangs in \`TaskGroup\` contexts where all tasks must complete before the group exits. Cleanup logic belongs in \`finally\` blocks, and \`CancelledError\` must propagate to the event loop to signal successful task termination.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:54:11.410657+00:00— report_created — created