我在Python中设置了一个计时器,假设是20秒,但在这两者之间,如果调用了另一个函数,则计时器应该会中断。
有没有办法使用Python的threading.Timer来执行此操作
发布于 2014-09-26 10:10:44
您可以在应该中断它的函数体中调用timer.cancel()。
def some_func():
print "Some function that runs after a timeout"
def interrupt_func():
timer.cancel() # some_func will no longer be called
# other stuff
timer = threading.Timer(20, some_func)
time.sleep(10)
interrupt_func()https://stackoverflow.com/questions/26050958
复制相似问题