Python中线程池与进程池实现并发应用
# 线程池需要导入的模块 from concurrent.futures import ThreadPoolExecutor # 进程池需要导入的模块 from concurrent.futures import ProcessPoolExecutor import time # 测试函数 def task(arg): print(arg) time.sleep(1) # 实例化线程池对象,最大并发数为10 pool=ThreadPoolExecutor(10) #pool.submit 参数为函数及所传参数 for i in range(100): pool.submit(task,i)
时间: 2024-11-09 02:02:03