proc.py 文件源码

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

项目:otest 作者: rohe 项目源码 文件源码
def find_test_instances(prog):
    pid = {}
    for proc in psutil.process_iter():
        _name = proc.name()
        if _name in ['python', 'python3', 'Python', 'Python3']:
            try:
                cmd = proc.cmdline()
            except psutil.AccessDenied:
                continue

            if len(cmd) > 5:
                if cmd[1].endswith(prog):
                    i = cmd.index('-i')
                    iss = cmd[i + 1]
                    i = cmd.index('-t')
                    tag = cmd[i + 1]
                    i = cmd.index('-p')
                    port = cmd[i + 1]
                    since = datetime.datetime.fromtimestamp(
                        proc.create_time()).strftime(
                        "%Y-%m-%d %H:%M:%S")
                    pid[proc.pid] = {'iss': iss, 'tag': tag, 'port': port,
                                     'since': since}
    return pid
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号