Skip to content

Commit aad2ecf

Browse files
authored
Merge pull request #958 from oremanj/cancelstatus
Refactor cancellation system to eagerly propagate effective state
2 parents 58d18d2 + 173da30 commit aad2ecf

File tree

5 files changed

+273
-166
lines changed

5 files changed

+273
-166
lines changed

docs/source/reference-core.rst

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -514,23 +514,7 @@ objects.
514514
exception, and (2) this scope is the one that was responsible
515515
for triggering this :exc:`~trio.Cancelled` exception.
516516

517-
.. attribute:: cancel_called
518-
519-
Readonly :class:`bool`. Records whether cancellation has been
520-
requested for this scope, either by an explicit call to
521-
:meth:`cancel` or by the deadline expiring.
522-
523-
This attribute being True does *not* necessarily mean that the
524-
code within the scope has been, or will be, affected by the
525-
cancellation. For example, if :meth:`cancel` was called after
526-
the last checkpoint in the ``with`` block, when it's too late to
527-
deliver a :exc:`~trio.Cancelled` exception, then this attribute
528-
will still be True.
529-
530-
This attribute is mostly useful for debugging and introspection.
531-
If you want to know whether or not a chunk of code was actually
532-
cancelled, then :attr:`cancelled_caught` is usually more
533-
appropriate.
517+
.. autoattribute:: cancel_called
534518

535519

536520
Trio also provides several convenience functions for the common

newsfragments/58.misc.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The plumbing of Trio's cancellation system has been substantially overhauled
2+
to improve performance and ease future planned improvements. Notably, there is
3+
no longer any internal concept of a "cancel stack", and checkpoints now take
4+
constant time regardless of the cancel scope nesting depth.

newsfragments/958.bugfix.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Inspecting the :attr:`~trio.CancelScope.cancel_called` attribute of a
2+
not-yet-exited cancel scope whose deadline is in the past now always
3+
returns ``True``, like you might expect. (Previously it would return
4+
``False`` for not-yet-entered cancel scopes, and for active cancel
5+
scopes until the first checkpoint after their deadline expiry.)

0 commit comments

Comments
 (0)