Python的进程池需要借用name方法来实现,具体内容如下

#!/usr/bin/env python
# -- coding = 'utf-8' --
# Author Allen Lee
# Python Version 3.5.1
# OS Windows 7
from multiprocessing import Pool
import time

def f1(arg):
    time.sleep(1)
    print(arg)

if __name__ == '__main__':
    pool = Pool(5)

    for i in range(30):
        pool.apply_async(func=f1,args=(i,))

    pool.close()#等待所有任务执行完毕
    #time.sleep(1)
    #pool.terminate() #立即终止
    pool.join()
    pass
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐