-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-116720: Fix corner cases of taskgroups #117407
Changes from all commits
90695c5
6c4876d
df6e8b7
c762e36
4989042
3f91f2d
55ff73f
50fd8d6
93ba76a
f1f89c0
48c6dda
1e20728
bc1522c
7f6e5ff
56251ff
c54fb22
6d4b3d7
b086609
8ac42f6
ac87a8e
be9365c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,6 +255,8 @@ def uncancel(self): | |
""" | ||
if self._num_cancels_requested > 0: | ||
self._num_cancels_requested -= 1 | ||
if self._num_cancels_requested == 0: | ||
self._must_cancel = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this also clear the cancel message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt it -- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay – I was just confused by that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you're right, that CLEAR is unnecessary there too. :-) |
||
return self._num_cancels_requested | ||
|
||
def __eager_start(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Improved behavior of :class:`asyncio.TaskGroup` when an external cancellation | ||
collides with an internal cancellation. For example, when two task groups | ||
are nested and both experience an exception in a child task simultaneously, | ||
it was possible that the outer task group would misbehave, because | ||
its internal cancellation was swallowed by the inner task group. | ||
|
||
In the case where a task group is cancelled externally and also must | ||
raise an :exc:`ExceptionGroup`, it will now call the parent task's | ||
:meth:`~asyncio.Task.cancel` method. This ensures that a | ||
:exc:`asyncio.CancelledError` will be raised at the next | ||
:keyword:`await`, so the cancellation is not lost. | ||
|
||
An added benefit of these changes is that task groups now preserve the | ||
cancellation count (:meth:`asyncio.Task.cancelling`). | ||
|
||
In order to handle some corner cases, :meth:`asyncio.Task.uncancel` may now | ||
reset the undocumented ``_must_cancel`` flag when the cancellation count | ||
reaches zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!