Python3 里面的线程池
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')
在这里
ThreadPoolExecutor 是封装了线程池
ProcessPoolExecutor 是封装了进程池
如果想用进程池。只需修改代码为
pool = ProcessPoolExecutor(10) #先定义一个进程池