• python3 获取子进程的name


    # coding:utf-8
    import os
    from multiprocessing import Process
    
    
    def func(n):
        print("子进程号: %s 参数: %s" % (os.getpid(), n))
    
    if __name__ == '__main__':
        print("主进程开始.")
        p_lst = []
        for i in range(10):
            p = Process(target=func, args=(i,))
            p.start()
            print("子进程%s名字:%s" % (i, p.name))
            p_lst.append(p)
    
        [pp.join() for pp in p_lst]
        print("主进程结束.")
    
    
    # 主进程开始.
    # 子进程0名字:Process-1
    # 子进程1名字:Process-2
    # 子进程2名字:Process-3
    # 子进程3名字:Process-4
    # 子进程4名字:Process-5
    # 子进程5名字:Process-6
    # 子进程6名字:Process-7
    # 子进程7名字:Process-8
    # 子进程8名字:Process-9
    # 子进程9名字:Process-10
    # 子进程号: 8552 参数: 0
    # 子进程号: 6904 参数: 1
    # 子进程号: 9156 参数: 2
    # 子进程号: 8664 参数: 3
    # 子进程号: 8560 参数: 4
    # 子进程号: 1028 参数: 6
    # 子进程号: 1940 参数: 7
    # 子进程号: 9084 参数: 5
    # 子进程号: 5172 参数: 8
    # 子进程号: 8320 参数: 9
    # 主进程结束.
  • 相关阅读:
    解决servlet在web.xml中的路径跳转问题
    浅谈上市公司期权
    spring 与mybatis 整合总结
    学习ssm心得
    django中ORM的事务操作
    Celery快速入门
    vagrant 使用指南
    数据库之mysql
    python之pip
    linux基础
  • 原文地址:https://www.cnblogs.com/lilyxiaoyy/p/10964630.html
Copyright © 2020-2023  润新知