In [1]:
from threading import Thread
def fun(t):
"""
//执行函数体
//t:时间
"""
v = int(9.8 * (t ** 2))
return v
class MyThread(Thread):
def __init__(self, time):
Thread.__init__(self)
self.time = None
self.result = None
self.time = time
def run(self):
self.result = fun(self.time)
def get_result(self):
return self.result
if __name__ == '__main__':
thread_ls = []
for i in range(10):
t = MyThread(time=i)
t.setDaemon(True)
thread_ls.append(t)
for t in thread_ls:
t.start()
for t in thread_ls:
t.join()
for t in thread_ls:
print(t.get_result())
quit()
0
9
39
88
156
245
352
480
627
793
标签:__,thread,python,self,线程,result,time,多线程,ls
From: https://www.cnblogs.com/ccxiaozhang/p/16792495.html