Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-113848: Handle CancelledError subclasses in asyncio TaskGroup() and timeout()#113850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletionsLib/asyncio/taskgroups.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -73,8 +73,10 @@ async def __aexit__(self, et, exc, tb):
self._base_error is None):
self._base_error = exc

propagate_cancellation_error = \
exc if et is exceptions.CancelledError else None
if et is not None and issubclass(et, exceptions.CancelledError):
propagate_cancellation_error = exc
else:
propagate_cancellation_error = None
if self._parent_cancel_requested:
# If this flag is set we *must* call uncancel().
if self._parent_task.uncancel() == 0:
Expand DownExpand Up@@ -133,7 +135,7 @@ async def __aexit__(self, et, exc, tb):
if propagate_cancellation_error and not self._errors:
raise propagate_cancellation_error

if et is not None andet isnot exceptions.CancelledError:
if et is not None and notissubclass(et,exceptions.CancelledError):
self._errors.append(exc)

if self._errors:
Expand Down
9 changes: 5 additions & 4 deletionsLib/asyncio/timeouts.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,10 +109,11 @@ async def __aexit__(
if self._state is _State.EXPIRING:
self._state = _State.EXPIRED

if self._task.uncancel() <= self._cancelling and exc_type is exceptions.CancelledError:
# Since there are no new cancel requests, we're
# handling this.
raise TimeoutError from exc_val
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
# handling this.
raise TimeoutError from exc_val
elif self._state is _State.ENTERED:
self._state = _State.EXITED

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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`.

[8]ページ先頭

©2009-2025 Movatter.jp