1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
import time,os,multiprocessing def work_a(): for i in range(10): print(i,'a',os.getpid()) time.sleep(1)
def work_b(): for i in range(10): print(i,'b',os.getpid()) time.sleep(1)
if __name__=='__main__': start = time.time() a_p = multiprocessing.Process(target=work_a) b_p = multiprocessing.Process(target=work_b) for p in (a_p,b_p): p.start() for p in (a_p,b_p): p.join() for p in (a_p,b_p): print(p.is_alive()) print('时间消耗是: ',time.time()-start) print('parent pid is %s' % os.getpid())
|