Python 进程池 pool


from multiprocessing import Process,Pool
import time,os

def Foo(i):
time.sleep(2)
print("in the Proess ",os.getpid())
return i
def Bar(arg):
print("-->exec done:",arg,os.getpid())

if __name__ == "__main__":
print("in the main process",os.getpid())
pool = Pool(3)
for i in range(10):
pool.apply_async(func=Foo,args=(i,),callback=Bar)
#pool.apply(func=Foo,args=(i,))
print("end")
pool.close()
pool.join()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM