Python 进程池

#coding=utf-8
from multiprocessing import Process,Pool,freeze_support
import time

def Fo(i):
    time.sleep(2)
    print('pool:')
    return i+10

def End(arg):
    print('--->done<---:',arg)


if __name__ == '__main__':
    freeze_support()        #windows上必须加上这一句否则会报错
    pool = Pool(3)
    for  i in range(10):
         pool.apply_async(func=Fo,args=(i,),callback=End)   #异步执行
         # pool.apply(func=Func,args=(i,))                      #同步
    print('end')
    pool.close()
    pool.join()          #进程池中执行完毕后再关闭,

你可能感兴趣的:(Python)