首页 > 编程语言 > 详细

Python Threading 模块计算所有线程的执行时间

时间:2021-04-10 00:02:52      阅读:24      评论:0      收藏:0      [点我收藏+]
import threading
import time

def run(n):
print("task",n)
time.sleep(1)

t_objs = []
start_time = time.time()
for i in range(1,6):
t = threading.Thread(target=run,args=("t-%s" %i,))
t.start()
t_objs.append(t)

for t in t_objs:
t.join()

print("-----all threads has finished-----")
print("cost:",time.time() - start_time)

Python Threading 模块计算所有线程的执行时间

原文:https://www.cnblogs.com/yx-book/p/14639008.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!