多线程获取返回值
有这样一个代码:
import threading
def aa(data):
return data
for i in range(5):
threading.Thread(target=aa, args=(i,)).start()
获取返回值:
import threading
import time
class Response:
responses = {}
def add_th(self, name, data):
self.responses[name] = data
def aa(name):
now = time.time()
response.add_th(name, now)
response = Response()
if __name__ == '__main__':
for i in range(5):
threading.Thread(target=aa, args=(i,)).start()
time.sleep(1)
print(response.responses)
运行结果:
本文来自博客园,作者:__username,转载请注明原文链接:https://www.cnblogs.com/code3/p/17392757.html