MCPcopy
hub / github.com/python-trio/trio / checkpoint

Function checkpoint

src/trio/_core/_run.py:3026–3061  ·  view source on GitHub ↗

A pure :ref:`checkpoint `. This checks for cancellation and allows other tasks to be scheduled, without otherwise blocking. Note that the scheduler has the option of ignoring this and continuing to run the current task if it decides this is appropriate (e.g. for increa

()

Source from the content-addressed store, hash-verified

3024
3025
3026async def checkpoint() -> None:
3027 """A pure :ref:`checkpoint <checkpoints>`.
3028
3029 This checks for cancellation and allows other tasks to be scheduled,
3030 without otherwise blocking.
3031
3032 Note that the scheduler has the option of ignoring this and continuing to
3033 run the current task if it decides this is appropriate (e.g. for increased
3034 efficiency).
3035
3036 Equivalent to ``await trio.sleep(0)`` (which is implemented by calling
3037 :func:`checkpoint`.)
3038
3039 """
3040 # The scheduler is what checks timeouts and converts them into
3041 # cancellations. So by doing the schedule point first, we ensure that the
3042 # cancel point has the most up-to-date info.
3043 await cancel_shielded_checkpoint()
3044 task = current_task()
3045 task._cancel_points += 1
3046 if task._cancel_status.effectively_cancelled or (
3047 task is task._runner.main_task and task._runner.ki_pending
3048 ):
3049 cs = CancelScope(deadline=-inf)
3050 if (
3051 task._cancel_status._scope._cancel_reason is None
3052 and task is task._runner.main_task
3053 and task._runner.ki_pending
3054 ):
3055 task._cancel_status._scope._cancel_reason = CancelReason(
3056 source="KeyboardInterrupt"
3057 )
3058 assert task._cancel_status._scope._cancel_reason is not None
3059 cs._cancel_reason = task._cancel_status._scope._cancel_reason
3060 with cs:
3061 await _core.wait_task_rescheduled(lambda _: _core.Abort.SUCCEEDED)
3062
3063
3064async def checkpoint_if_cancelled() -> None:

Callers 1

Calls 4

current_taskFunction · 0.85
CancelScopeClass · 0.85
CancelReasonClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…