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 # 主進程結束.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM