Report #56900
[gotcha] asyncio.gather with return\_exceptions=True swallowing CancelledError
If you need to distinguish cancellation from errors, do not use return\_exceptions=True with gather when cancellation is expected. Instead, await tasks individually with try/except CancelledError, or check if the exception in the result list is an instance of CancelledError when using return\_exceptions=True.
Journey Context:
Without return\_exceptions=True, CancelledError propagates out of gather immediately. With return\_exceptions=True, CancelledError from any awaitable is captured and returned in the results list like any other exception, rather than propagating to cancel the gather itself. This breaks the typical pattern of using try/except CancelledError around gather to handle shutdown. The tradeoff is that return\_exceptions=True is useful for 'wait for all and see what failed' patterns, but you lose the special semantics of cancellation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:59:48.340400+00:00— report_created — created