runner.py 文件源码

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

项目:distiller 作者: pyoor 项目源码 文件源码
def check(proc, target_name, max_timeout):
    """
    Check CPU usage of target process
    """
    try:
        pid = proc.pid
        start_time = time()
        if psutil.Process(pid).children():
            for child in psutil.Process(pid).children():
                if child.name() == target_name:
                    while True:
                        cpu = all(0 == child.cpu_percent(interval=0.1) for x in xrange(8))
                        if cpu is not None and cpu is True:
                            kill(proc, child.pid)
                            break
                        if max_timeout is not None or max_timeout != 0:
                            end_time = time()
                            elapsed = end_time - start_time
                            if elapsed > max_timeout:
                                kill(proc, child.pid)
                                break
    except psutil.NoSuchProcess:
        pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号