有这样一个代码:
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)
运行结果:
标签:aa,__,name,threading,获取,time,返回值,多线程,data From: https://www.cnblogs.com/code3/p/17392757.html