赞
踩
""" 探索pool.map多进程执行方式的实质 """ from multiprocessing import Pool from time import sleep from datetime import datetime class forMap: def __init__(self): self.name = '没啥用的初始化' def forPrinit(self, i): sleep(i) print(i) return i ** 2 if __name__ == '__main__': s = datetime.now() tt = forMap() # 进程池中创建三个进程 p = Pool(3) l = [2, 4, 6] rList = p.map(tt.forTest, l) print(rList) p.close() p.join() e = datetime.now() print('多进程执行时间:', e - s) 2 4 6 [4, 16, 36] 多进程执行时间: 0:00:06.273263
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。