获取线程的执行结果
2021-03-08 23:29
标签:app wrapper append 运行时间 out name display rgba thread 获取线程的执行结果 标签:app wrapper append 运行时间 out name display rgba thread 原文地址:https://www.cnblogs.com/sea-stream/p/14192614.htmlimport threading
from queue import Queue
import time
def timeit(f):
def wrapper(*args, **kwargs):
start_time = time.time()
res = f(*args, **kwargs)
end_time = time.time()
print("%s函数运行时间:%.8f" % (f.__name__, end_time - start_time))
return res
return wrapper
def job(li, queue):
queue.put(sum(li))
@timeit
def use_thread():
q = Queue()
lis = [range(5), range(2,10), range(1000, 20000), range(3000, 10000)]
threads = []
for li in lis:
t = threading.Thread(target=job, args=(li, q))
t.start()
threads.append(t)
[thread.join() for thread in threads]
results = [q.get() for li in lis]
print(results)
if __name__ == "__main__":
use_thread()
macname@MacdeMacBook-Pro py % python3 cccccc.py
[10, 44, 199490500, 45496500]
use_thread函数运行时间:0.00095630
macname@MacdeMacBook-Pro py %
上一篇:python中字符串的常用拼接
下一篇:Mybatis整合Spring