进程池

import time
from multiprocessing import Process,Pool

def Foo(i):
    time.sleep(1)
    print(i)

def Bar(arg):
    print('hello')


if __name__ == '__main__':
    pool = Pool(5) #进程池的容量是5

    for i in range(100):
        pool.apply_async(func=Foo,args=(i,),callback=Bar) #callback是回调函数 

    pool.close()
    pool.join()

    print('end---')

 

posted @ 2018-05-07 15:01  阜阳小全  阅读(86)  评论(0编辑  收藏  举报