aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/asyncio/taskgroups.py
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-08-04 19:27:44 +0530
committerGitHub <noreply@github.com>2022-08-04 06:57:44 -0700
commit2fef27589e44c91042c2598b5cad6c6ad0516d93 (patch)
treef89eabbb1b1eda7fe58b7628e1fce02dfd308314 /Lib/asyncio/taskgroups.py
parent42b102bbf9a9ae6fae8f6710202fb7afeeac277c (diff)
downloadcpython-2fef27589e44c91042c2598b5cad6c6ad0516d93.tar.gz
cpython-2fef27589e44c91042c2598b5cad6c6ad0516d93.zip
GH-95289: Always call uncancel() when parent cancellation is requested (#95602)
Co-authored-by: Guido van Rossum <guido@python.org>
Diffstat (limited to 'Lib/asyncio/taskgroups.py')
-rw-r--r--Lib/asyncio/taskgroups.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py
index 3ca65062efd..097b4864f7a 100644
--- a/Lib/asyncio/taskgroups.py
+++ b/Lib/asyncio/taskgroups.py
@@ -54,21 +54,22 @@ class TaskGroup:
async def __aexit__(self, et, exc, tb):
self._exiting = True
- propagate_cancellation_error = None
if (exc is not None and
self._is_base_error(exc) and
self._base_error is None):
self._base_error = exc
- if et is not None:
- if et is exceptions.CancelledError:
- if self._parent_cancel_requested and not self._parent_task.uncancel():
- # Do nothing, i.e. swallow the error.
- pass
- else:
- propagate_cancellation_error = exc
+ propagate_cancellation_error = \
+ exc if et is exceptions.CancelledError else None
+ if self._parent_cancel_requested:
+ # If this flag is set we *must* call uncancel().
+ if self._parent_task.uncancel() == 0:
+ # If there are no pending cancellations left,
+ # don't propagate CancelledError.
+ propagate_cancellation_error = None
+ if et is not None:
if not self._aborting:
# Our parent task is being cancelled:
#