from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor import time def task(i): print(i) time.sleep(1) pool = ThreadPoolExecutor(10) #先定義一個線程池 for index in range(64): pool.submit(task,index) print('end')
在這裏 spa
ThreadPoolExecutor 是封裝了線程池線程
ProcessPoolExecutor 是封裝了進程池code
若是想用進程池。只需修改代碼爲blog
pool = ProcessPoolExecutor(10) #先定義一個進程池