python从子线程中获得返回值的方法
时间:2021-04-23 09:28:31|栏目:Python代码|点击: 次
如下所示:
# coding:utf-8
import time
from threading import Thread
def foo(number):
time.sleep(20)
return number
class MyThread(Thread):
def __init__(self, number):
Thread.__init__(self)
self.number = number
def run(self):
self.result = foo(self.number)
def get_result(self):
return self.result
thd1 = MyThread(3)
thd2 = MyThread(5)
thd1.start()
thd2.start()
thd1.join()
thd2.join()
print thd1.get_result()
print thd2.get_result()
上一篇:Python bytes string相互转换过程解析
栏 目:Python代码
本文标题:python从子线程中获得返回值的方法
本文地址:http://www.codeinn.net/misctech/107009.html






