如何理解接口幂等性
387
2022-09-04
python 线程池计数(python怎么读)
使用ThreadPoolExecutor执行任务,来统计显示执行进度,执行耗时
from concurrent.futures import ThreadPoolExecutor, as_completedimport timeimport uuiddef vm_one(uuid ,start_time): time.sleep(1) global c global total c = c+1 print("index:{}/{},value:{},time:{:.3f}".format(c,total,uuid,time.time()-start_time)) return uuidif __name__ == '__main__': start_time = time.time() c = 0 uuids = [uuid.uuid4() for _ in range(0,100)] total = len(uuids) with ThreadPoolExecutor(max_workers=10) as pool: all_task = [pool.submit(vm_one, uid,start_time) for uid in uuids] all_data = [] for out in as_completed(all_task): mess = out.result() all_data.append(mess)
输出结果:
E:\myproject\venv\Scripts\python.exe E:/myproject/base_info/convert.pyindex:1/100,value:e6c6cca1-7400-4459-9fc6-59d136577219,time:1.009index:2/100,value:bc105fb7-69e4-4573-8816-9aa89065045e,time:1.009..............index:91/100,value:8fd4858e-84f7-499f-b8db-39a7d33c35d9,time:10.049index:92/100,value:bc42179e-e16d-4baf-b677-2729da753037,time:10.049index:93/100,value:a7751a37-0688-43a2-9f95-ee7784c7557d,time:10.049index:94/100,value:9b37e1bb-1999-48d1-9ffd-ecbda2b26152,time:10.049index:95/100,value:ba4e321d-0d11-4233-a142-af7ba89aeb60,time:10.049index:96/100,value:2fd39b41-f7f6-43a7-8953-100514b204d4,time:10.065index:97/100,value:954b59af-e4af-484a-9964-b3180ceae8a2,time:10.065index:98/100,value:9a8745de-c3e0-46f6-aa4a-6b8b29d2061e,time:10.065index:99/100,value:73c9e176-1307-426a-8be6-8296cd87a2df,time:10.065index:100/100,value:e0d98ebf-9102-42db-a018-da5b2b5d9355,time:10.065Process finished with exit code 0
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~