profiler.py 文件源码

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

项目:raiden 作者: raiden-network 项目源码 文件源码
def greenlet_profiler(event, args):
    if event in ('switch', 'throw'):  # both events are in the target context
        now = clock()

        try:
            # we need to account the time for the user function
            frame = sys._getframe(1)
        except ValueError:
            # the first greenlet.switch() and when the greenlet is being
            # destroied there is nothing more in the stack, so this function is
            # the first function called
            frame = sys._getframe(0)

        origin, target = args

        origin_state = _state[origin]
        target_state = ensure_thread_state(target, frame)

        origin_state.switch_enter(now)  # origin is entering the "sleep" state
        target_state.switch_exit(now)   # target might be leaving the "sleep"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号