mirror of
https://github.com/python/cpython.git
synced 2025-12-05 00:52:25 +00:00
gh-113848: Handle CancelledError subclasses in asyncio TaskGroup() and timeout() (GH-113850)
This commit is contained in:
parent
5273655bea
commit
a5db6a3351
3 changed files with 13 additions and 7 deletions
|
|
@ -73,8 +73,10 @@ class TaskGroup:
|
||||||
self._base_error is None):
|
self._base_error is None):
|
||||||
self._base_error = exc
|
self._base_error = exc
|
||||||
|
|
||||||
propagate_cancellation_error = \
|
if et is not None and issubclass(et, exceptions.CancelledError):
|
||||||
exc if et is exceptions.CancelledError else None
|
propagate_cancellation_error = exc
|
||||||
|
else:
|
||||||
|
propagate_cancellation_error = None
|
||||||
if self._parent_cancel_requested:
|
if self._parent_cancel_requested:
|
||||||
# If this flag is set we *must* call uncancel().
|
# If this flag is set we *must* call uncancel().
|
||||||
if self._parent_task.uncancel() == 0:
|
if self._parent_task.uncancel() == 0:
|
||||||
|
|
@ -133,7 +135,7 @@ class TaskGroup:
|
||||||
if propagate_cancellation_error and not self._errors:
|
if propagate_cancellation_error and not self._errors:
|
||||||
raise propagate_cancellation_error
|
raise propagate_cancellation_error
|
||||||
|
|
||||||
if et is not None and et is not exceptions.CancelledError:
|
if et is not None and not issubclass(et, exceptions.CancelledError):
|
||||||
self._errors.append(exc)
|
self._errors.append(exc)
|
||||||
|
|
||||||
if self._errors:
|
if self._errors:
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,8 @@ class Timeout:
|
||||||
if self._state is _State.EXPIRING:
|
if self._state is _State.EXPIRING:
|
||||||
self._state = _State.EXPIRED
|
self._state = _State.EXPIRED
|
||||||
|
|
||||||
if self._task.uncancel() <= self._cancelling and exc_type is exceptions.CancelledError:
|
if self._task.uncancel() <= self._cancelling and exc_type is not None:
|
||||||
|
if issubclass(exc_type, exceptions.CancelledError):
|
||||||
# Since there are no new cancel requests, we're
|
# Since there are no new cancel requests, we're
|
||||||
# handling this.
|
# handling this.
|
||||||
raise TimeoutError from exc_val
|
raise TimeoutError from exc_val
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
:func:`asyncio.TaskGroup()` and :func:`asyncio.timeout()` context managers
|
||||||
|
now handle :exc:`~asyncio.CancelledError` subclasses as well as exact
|
||||||
|
:exc:`!CancelledError`.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue