# coding:utf-8
# 线程池使用方法
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor # 线程池,进程池
from multiprocessing import cpu_count # 取得本机的cpu核数
if __name__ == '__main__':
# 线程池
t = ThreadPoolExecutor(max_workers=cpu_count() * 2) # 本机cpu核数的2-5倍可以最大发挥电脑的性能
for i in range(22, 1325):
t.submit(get_info, i) # 要执行函数,以及传入的参数
t.shutdown() # 等线程跑完再向下走
版权归属:
海绵
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区