-
Notifications
You must be signed in to change notification settings - Fork 70
Cannot catch KeyboardInterrupt on blocking icon.run() call #177
Description
Hey :)
I want to use this in a tray-only script, so I attempt to block it. Some extra logic runs on a different thread that must be shutdown properly, so I have to catch ctrl+c, but it doesn't work:
try:
icon.run()
except KeyboardInterrupt:
print("Catched KeyboardInterrupt...")
finally:
print("Shutting down...")The icon shows up, but hitting ctrl+c will crash icon.run and subsequently the entire process, icon.run does not raise KeyboardInterrupt or allows to continue operation, so all my sibling workers crash, too.
I tried to introduce signals, but icon.run is blocking on the main thread and thus takes precedence when sending the SIGINT. I also tried to spawn icon.run_detached in another thread, but this seems to only work if I have a mainloop in a GUI framework on the main thread, such as Tkinter, but I don't have that, so icon.run() should clearly be my mainloop.
I'm testing this on MacOS.