Report #57477
[gotcha] asyncio.gather with return\_exceptions=True masks CancelledError as result
When checking for cancellation after gather returns, inspect the result list for instances of asyncio.CancelledError rather than relying on task.cancelled\(\) or checking for exceptions generically.
Journey Context:
With return\_exceptions=True, CancelledError raised in a task is caught and placed in the results list at the task's index position. Code checking 'if task.exception\(\)' or 'if task.cancelled\(\)' after gather will miss that the task was actually cancelled, because the exception was consumed. This breaks cleanup logic that expects cancelled tasks to be identified via the cancelled\(\) method.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:57:52.844491+00:00— report_created — created