Puse un temporizador en Python para, digamos, 20 segundos, pero entre si se llama a otra función, el temporizador debería interrumpirse.
¿Hay alguna manera de ejecutar esto usando Python "s threading.Timer
?
Respuestas
0 para la respuesta № 1Puedes llamar timer.cancel()
En el cuerpo de la función que debe interrumpirlo.
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()