I have been banging my head against this all Labor Day long weekend. The code below does not stop with Ctrl-C. I must be doing something brain dead and can't see it anymore. Not only does it not stop, but I never get the signal handler message,
"Interrupted by %d, shutting down"
I hear terms like "blocked," but I don't know what they mean. Is my SIGTERM somehow "blocked"? I also do not understand the difference between killpill.wait and killpill.is_set(). But, that seems like a secondary problem. Since I never seem to catch the SIGTERM, the killpill method shouldn't matter.
I am using Python 3.8.5 on Windows 10, running in PowerShell.
import signal
import logging
import threading
logging.basicConfig(level=logging.DEBUG,
format='[%(levelname)s] (%(threadName)-10s) %(message)s')
def quit(signo, _frame): # Graceful exit when we get ^C
print("Interrupted by %d, shutting down" % signo)
killpill.set()
def doit():
try:
while not(killpill.wait(1)):
logging.debug( "starting ... " + str( killpill.is_set() ))
time.sleep(1)
logging.debug( "working ... " + str( killpill.is_set()) )
except KeyboardInterrupt:
logging.debug("KeyboardInterrupt stopping mouse_info")
def main():
global killpill
killpill = threading.Event()
t1=threading.Thread(name='t1',target=doit)
t1.daemon=True
t1.start()
t1.join()
while True:
time.sleep(1)
if (__name__ == '__main__'):
for sig in ('TERM', 'INT', 'BREAK', 'ABRT'):
signal.signal(getattr(signal, 'SIG'+sig), quit)
main()
Any helpful insight would be greatly appreciated. The output is
[DEBUG] (t1 ) working ... False
[DEBUG] (t1 ) starting ... False
[DEBUG] (t1 ) working ... False
[DEBUG] (t1 ) starting ... False