python 进程池(并行编程 21)

2019-07-30 10:51:02 浏览数 (1)

import multiprocessing def function_square(data): result=data*data return result

if name=="main": inputs=list(range(100)) pool=multiprocessing.Pool(processes=4) outs=pool.map(function_square,inputs) pool.close() pool.join() print(outs)

Pool的四个方法:map,map_async()异步,不会阻塞主进程。 apply() apply_async()

0 人点赞