@@ -119,7 +119,7 @@ def run_in_system_nursery(self, token: TrioToken) -> None:
119
119
def in_trio_thread () -> None :
120
120
try :
121
121
trio .lowlevel .spawn_system_task (
122
- self .run , name = self .afn , context = self .context
122
+ self .run_system , name = self .afn , context = self .context
123
123
)
124
124
except RuntimeError : # system nursery is closed
125
125
self .queue .put_nowait (
@@ -394,10 +394,16 @@ def from_thread_check_cancelled() -> None:
394
394
395
395
.. note::
396
396
397
- The check for cancellation attempts of ``cancellable=False`` threads is
398
- interrupted while executing ``from_thread.run*`` functions, which can lead to
399
- edge cases where this function may raise or not depending on the timing of
400
- :class:`~trio.CancelScope` shields being raised or lowered in the Trio threads.
397
+ To be precise, :func:`~trio.from_thread.check_cancelled` checks whether the task
398
+ running :func:`trio.to_thread.run_sync` has ever been cancelled since the last
399
+ time it was running a :func:`trio.from_thread.run` or :func:`trio.from_thread.run_sync`
400
+ function. It may raise `trio.Cancelled` even if a cancellation occurred that was
401
+ later hidden by a modification to `trio.CancelScope.shield` between the cancelled
402
+ `~trio.CancelScope` and :func:`trio.to_thread.run_sync`. This differs from the
403
+ behavior of normal Trio checkpoints, which raise `~trio.Cancelled` only if the
404
+ cancellation is still active when the checkpoint executes. The distinction here is
405
+ *exceedingly* unlikely to be relevant to your application, but we mention it
406
+ for completeness.
401
407
"""
402
408
try :
403
409
raise_cancel = PARENT_TASK_DATA .cancel_register [0 ]
@@ -456,7 +462,10 @@ def from_thread_run(
456
462
RunFinishedError: if the corresponding call to :func:`trio.run` has
457
463
already completed, or if the run has started its final cleanup phase
458
464
and can no longer spawn new system tasks.
459
- Cancelled: if the task enters cancelled status or call to :func:`trio.run`
465
+ Cancelled: If the original call to :func:`trio.to_thread.run_sync` is cancelled
466
+ (if *trio_token* is None) or the call to :func:`trio.run` completes
467
+ (if *trio_token* is not None) while ``afn(*args)`` is running,
468
+ then *afn* is likely to raise
460
469
completes while ``afn(*args)`` is running, then ``afn`` is likely to raise
461
470
:exc:`trio.Cancelled`.
462
471
RuntimeError: if you try calling this from inside the Trio thread,
0 commit comments