GH-95289: Always call uncancel() when parent cancellation is requested (GH-95602)

Co-authored-by: Guido van Rossum <guido@python.org>
(cherry picked from commit 2fef27589e)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2022-08-04 07:50:54 -07:00 committed by GitHub
parent f2926358d1
commit 2d84fe59c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 9 deletions

View file

@ -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:
#