此处的类用于工作站,此处仅部分代码可提高可读性。
功能checkIdletime用于计算空闲时间并在工作站空闲时间过长时显示警告。我希望此函数与其他一些进程一起在后台运行,所以我在线程中运行它。
class Workstation:
def __init__(self, workstationID):
self.workstationID = workstationID
self.state = "Idle"
self.idleStart = time.clock()
def forceIdle(self):
self.state = "Idle"
self.idleStart= time.clock()
def checkIdleTime(idleStart):
while(1):
idleEnd= time.clock()
idleTime= idleEnd-idleStart
if (idleTime>y):
print("Idle Time is greater than " + str(y))
elif (idleTime>x):
print("Idle Time is greater than " + str(x))
下面的W1是我初始化的工作站,这时设置了idleStart时钟。在另一个线程中,我调用函数forceIdle来重置idleStart。我下面的线程无法检测到此更改。
t1= threading.Thread(target= checkIdleTime, args=(W1.idleStart,))
t1.start()