1 from multiprocessing import Pool 2 from time import sleep 3 def Foo(i): 4 sleep(1) 5 print(i) 6 7 8 if __name__ == "__main__": 9 #5个线程会同时执行10 pool = Pool(5)11 12 for i in range(50):13 #从进程池中申请进程,还可以传入callback参数作为进程结束后的回调函数14 pool.apply_async(func=Foo, args=(i,))15 pool.close()16 pool.join()