我编写了一个简单的线程类,它监视两个参数。当我命令两个线程开始命令时,我没有得到任何错误,但是,对我的第二个线程的调用似乎没有执行。这是我的课:
import threading
import time
from SHFramework import SH
class CLSThread():
def __init__(self):
self.tsh = SH()
self.tsh.StartServer()
self.GetStatusThread1 = threading.Thread(target=self.GetTemperature())
self.GetStatusThread2 = threading.Thread(target=self.GetX())
def GetTemperature(self):
while True:
temp_val = self.tsh.GetValue("Temperature")
print("value from {}:".format("Temperature")
print str(temp_val)
def GetX(self):
while True:
x_val = self.tsh.GetValue("X")
print("value from {}:".format("X")
print str(x_val)
clst1 = CLSThread()
clst1.GetStatusThread1.start()
clst2.GetStatusThread2.start()
当我命令'clst1.GetStatusThread1.start()'
时,它会很好地输出来自GetTemperature
的结果。但是,我不知道它是否曾经命令过GetX
,因为它从不打印该方法的结果。虽然,当我从这两个方法中去掉while True:
语句,只保留后面的行时,它确实打印出了这两个方法的结果(clst1.GetStatusThread1.start()
,clst2.GetStatusThread2.start()
)
目前没有回答
相关问题 更多 >
编程相关推荐