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()