_run.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:trio 作者: python-trio 项目源码 文件源码
def checkpoint_if_cancelled():
    """Issue a :ref:`checkpoint <checkpoints>` if the calling context has been
    cancelled.

    Equivalent to (but potentially more efficient than)::

        if trio.current_deadline() == -inf:
            await trio.hazmat.checkpoint()

    This is either a no-op, or else it allow other tasks to be scheduled and
    then raises :exc:`trio.Cancelled`.

    Typically used together with :func:`cancel_shielded_checkpoint`.

    """
    task = current_task()
    if (task._pending_cancel_scope() is not None or
        (task is task._runner.main_task and task._runner.ki_pending)):
        await _core.checkpoint()
        assert False  # pragma: no cover
    task._cancel_points += 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号