forked from python-trio/trio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor cancellation system to eagerly propagate effective state
This synthesizes the ideas that arose in the discussion on python-trio#910. Each CancelScope `with` block now creates a CancelStatus object (not exposed publicly); the CancelStatus objects know their parent/child relationships in the lexical nesting tree of CancelScope contexts, and communicate to propagate cancellation information eagerly. The upshot is that the question "is this task in a cancelled scope right now?" can now be answered in O(1) time, eliminating a notable inefficiency in Trio's run loop. As a nice side benefit, manipulations of the cancellation tree such as are required by `nursery.start()` become much easier to reason about.
- Loading branch information
Showing
5 changed files
with
287 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
The plumbing of Trio's cancellation system has been substantially overhauled | ||
to improve performance and ease future planned improvements. Notably, there is | ||
no longer any internal concept of a "cancel stack", and checkpoints now take | ||
constant time regardless of the cancel scope nesting depth. |
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,4 @@ | ||
Inspecting the :attr:`~trio.CancelScope.cancel_called` attribute of a | ||
not-yet-entered cancel scope whose deadline is in the past now returns | ||
``True``, like you might expect. (Previously it would return ``False`` | ||
due to an artifact of the mechanism used to track deadline expiries.) |
Oops, something went wrong.