Python Threading 模块计算所有线程的执行时间
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)