0%
简介
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 33 34 35 36
|
import multiprocessing , os, time
def work(count,lock): lock.acquire() print(count,os.getpid()) time.sleep(5) lock.release() return 'result is %s, pid is %s' %(count,os.getpid())
if __name__=='__main__': start = time.time() pool = multiprocessing.Pool(5) manger = multiprocessing.Manager() lock = manger.Lock()
for i in range(5): result = pool.apply_async(func= work,args=(i,lock)) pool.close() pool.join() master_consume_time = time.time()-start print(master_consume_time)
|