我有一个简单的python类Timer_u,它以秒为单位,在后台运行计时器。完成后,它运行一个返回true的finished函数。当计时器以变量的形式停止时,如何获得这个函数的值?谢谢您!在
import threading
class Timer_():
def __init__(self, interval):
#interval in seconds
self.interval = interval
self.finished = False
def run(self):
self.timel = threading.Timer(float(self.interval), self.finish)
self.timel.start()
def finish(self):
self.finished = True
return True
def cancel(self):
self.timel.cancel()
time = Timer_(5)
time.run()
print(time.finished)
听起来你想等到
time.finished
是True
尝试对
time.finished
的值使用while循环:这将在while中循环,直到
timer.finished
为True
,然后您可以将该值用作变量或继续。在相关问题 更多 >
编程相关推荐