1 # coding:utf-8 2 3 import time 4 import os 5 def work_a(): 6 for i in range(3): 7 print(i,"a",os.getpid()) #os.getpid()获取进程id 8 time.sleep(1) 9 10 def work_b(): 11 for i in range(3): 12 print(i,"b",os.getpid()) 13 time.sleep(1) 14 15 if __name__==\'__main__\': 16 start=time.time() 17 work_a() 18 work_b() 19 end=time.time()-start 20 print(end) 21 print(\'parent pid is %s\' % os.getpid()) 22 \'\'\' 23 0 a 36436 24 1 a 36436 25 2 a 36436 26 0 b 36436 27 1 b 36436 28 2 b 36436 29 6.002437114715576 30 parent pid is 36436 所有的进程id跟主进程一致,都是36436 31 \'\'\'
Python语法进阶(1)- 进程与线程编程 (2)
内容版权声明:除非注明,否则皆为本站原创文章。