Refactor cancellation system to eagerly propagate effective state#958
Refactor cancellation system to eagerly propagate effective state#958njsmith merged 5 commits intopython-trio:masterfrom
Conversation
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.
Codecov Report
@@ Coverage Diff @@
## master #958 +/- ##
==========================================
+ Coverage 99.53% 99.53% +<.01%
==========================================
Files 102 102
Lines 12272 12301 +29
Branches 914 919 +5
==========================================
+ Hits 12215 12244 +29
Misses 36 36
Partials 21 21
|
|
I haven't had energy to do a detailed review yet, but a few quick thoughts:
|
|
Making CancelStatus have-a CancelScope definitely makes the code clearer; thanks for the suggestion! The name I don't think we can quite simplify |
|
Iowa midnight strikes again? |
|
Booyah. |
This synthesizes the ideas that arose in the discussion on #910.
Each CancelScope
withblock 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.
Fixes #58.