python multiprocessing Pool 多进程池

过程

1.引入模块
2.实例化Pool
3.向Pool提交任务
4.关闭进程池
5.join进程同步

Demo

from multiprocessing import Pool
import os , time, random

def run_task(name):
   pass
if __name__ ==  '__main__':
    p = Pool(process=3)
    for i in range(10):
        p.apply_async(run_task, args=(str(i), ))
    print  'Waiting for all subprocesses done...'
    p.close()
    p.join()
    print 'All subprocesses done.'
     

你可能感兴趣的:(python multiprocessing Pool 多进程池)