线程池使用
创建线程的使用
from concurrent.futures import ThreadPoolExecutor,as_completed executor=ThreadPoolExecutor(max_workers=10) def func(s,n): print(s,n) return s,n item_lst = [1,3,4,5,6,7,8] all_task=[executor.submit(func,item,3) for item in item_lst] # 加载任务 for task in as_completed(all_task): s,n=task.result() # 获取执行结果
参考文章:https://www.jianshu.com/p/b9b3d66aa0be