-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This prevents external cancellations of a task group's parent task to be dropped when an internal cancellation happens at the same time. Also strengthen the semantics of uncancel() to clear self._must_cancel when the cancellation count reaches zero. Co-Authored-By: Tin Tvrtković <tinchester@gmail.com> Co-Authored-By: Arthur Tacca
- Loading branch information
1 parent
22b25d1
commit fa58e75
Showing
8 changed files
with
183 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Misc/NEWS.d/next/Library/2024-04-04-15-28-12.gh-issue-116720.aGhXns.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters