美文网首页
python multiprocessing Pool 多进程池

python multiprocessing Pool 多进程池

作者: 我的名字是常量吗 | 来源:发表于2017-11-06 13:51 被阅读0次

过程

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 多进程池

      本文链接:https://www.haomeiwen.com/subject/tuxlmxtx.html