线程池: 一个容器,这个容器限制住你开启线程的数量
以时间换空间
from concurrent.futures import ProcessPoolExecutor,ThreadPoolExecutor
import os,time,random
def task():
print(f'{os.getpid()}接客')
time.sleep(random.randint(1,3))
if __name__ == '__main__':
p = ProcessPoolExecutor() # 默认不写,进程池里面的进程数与CPU个数相等
for i in range(20):
p.submit(task)
t = ThreadPoolExecutor() # 默认不写,线程数为CPU个数*5
for i in range(20):
t.submit(task)