Skip to content

Commit 131b0b8

Browse files
committed
propagate the original CancelledError
1 parent 3b776cf commit 131b0b8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/asyncio/taskgroups.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ async def _aexit(self, et, exc):
116116
# can be cancelled multiple times if our parent task
117117
# is being cancelled repeatedly (or even once, when
118118
# our own cancellation is already in progress)
119+
pending_cancellation_error = None
119120
while self._tasks:
120121
if self._on_completed_fut is None:
121122
self._on_completed_fut = self._loop.create_future()
122123

123124
try:
124125
await self._on_completed_fut
125126
except exceptions.CancelledError as ex:
127+
pending_cancellation_error = ex
126128
if not self._aborting:
127129
# Our parent task is being cancelled:
128130
#
@@ -151,9 +153,9 @@ async def _aexit(self, et, exc):
151153
# If there are no pending cancellations left,
152154
# don't propagate CancelledError.
153155
propagate_cancellation_error = None
154-
else:
156+
elif propagate_cancellation_error is None:
155157
# gh-155433: the remaining cancellation is not ours, don't drop it
156-
propagate_cancellation_error = exceptions.CancelledError()
158+
propagate_cancellation_error = pending_cancellation_error
157159

158160
# Propagate CancelledError if there is one, except if there
159161
# are other errors -- those have priority.

0 commit comments

Comments
 (0)