Readonly :class:`bool`. Records whether cancellation has been requested for this scope, either by an explicit call to :meth:`cancel` or by the deadline expiring. This attribute being True does *not* necessarily mean that the code within the scope has been, or will be
(self)
| 954 | |
| 955 | @property |
| 956 | def cancel_called(self) -> bool: |
| 957 | """Readonly :class:`bool`. Records whether cancellation has been |
| 958 | requested for this scope, either by an explicit call to |
| 959 | :meth:`cancel` or by the deadline expiring. |
| 960 | |
| 961 | This attribute being True does *not* necessarily mean that the |
| 962 | code within the scope has been, or will be, affected by the |
| 963 | cancellation. For example, if :meth:`cancel` was called after |
| 964 | the last checkpoint in the ``with`` block, when it's too late to |
| 965 | deliver a :exc:`~trio.Cancelled` exception, then this attribute |
| 966 | will still be True. |
| 967 | |
| 968 | This attribute is mostly useful for debugging and introspection. |
| 969 | If you want to know whether or not a chunk of code was actually |
| 970 | cancelled, then :attr:`cancelled_caught` is usually more |
| 971 | appropriate. |
| 972 | """ |
| 973 | if ( # noqa: SIM102 # collapsible-if but this way is nicer |
| 974 | self._cancel_status is not None or not self._has_been_entered |
| 975 | ): |
| 976 | # Scope is active or not yet entered: make sure cancel_called |
| 977 | # is true if the deadline has passed. This shouldn't |
| 978 | # be able to actually change behavior, since we check for |
| 979 | # deadline expiry on scope entry and at every checkpoint, |
| 980 | # but it makes the value returned by cancel_called more |
| 981 | # closely match expectations. |
| 982 | if not self._cancel_called and current_time() >= self._deadline: |
| 983 | self._cancel(CancelReason(source="deadline")) |
| 984 | return self._cancel_called |
| 985 | |
| 986 | |
| 987 | ################################################################ |
nothing calls this directly
no test coverage detected