I have a function I'm calling every 5 seconds like such:
def check_buzz(super_buzz_words):
print 'Checking buzz'
t = Timer(5.0, check_buzz, args=(super_buzz_words,))
t.dameon = True
t.start()
buzz_word = get_buzz_word()
if buzz_word is not 'fail':
super_buzz_words.put(buzz_word)
main()
check_buzz()
I'm exiting the script by either catching a KeyboardInterrupt or by catching a System exit and calling this:
sys.exit('\nShutting Down\n')
I'm also restarting the program every so often by calling:
execv(sys.executable, [sys.executable] + sys.argv)
My question is, how do I get that timer thread to shut off? If I keyboard interrupt, the timer keeps going.
atexitthat callst.cancel()?sys.exit()takes an integer error code. And you can callt.cancel().Timerobj, but considering the thread is adameonwouldn't it shut down with the rest of the script?sys.exit?sys.exitjust raisesSystemExitso if you are also catchingSystemExityou may have a problem with that handler. The script and the timer should be gone when you call exit.