rumps icon indicating copy to clipboard operation
rumps copied to clipboard

Custom handler for KeyboardInterrupt

Open jabbson opened this issue 2 years ago • 3 comments

I am looking for a way to handle KeyboardInterrupt to gracefully shutdown the app and preserve data/progress. For example the app keeps track of events and I would like to pickle them before shutting down if the app was stopped by Ctrl-c. Is there a way to do that?

jabbson avatar Jul 18 '23 02:07 jabbson

would second this, but ".quit_application()" doesn't seem to work for me at all. however letting the app populate with the default quit button and choosing that works every time, but unfortunately i have a function that is needed as part of the quit process.

rumps also seems to over ride my own signal handler.

porovaara avatar Apr 03 '24 12:04 porovaara

Can't edit my above comment. rumps seems to conflict with NSWorkspace functionality from Appkit as well.

porovaara avatar Apr 03 '24 12:04 porovaara

Applications can register a callback to the before_quit EventEmitter, which will be called when a KeyboardInterrupt (SIG_INT) is raised.

def my_interrupt_handler(*args, **kwargs): print('Cleanup')

rumps.events.before_quit.register(my_interrupt_handler)

awschmeder avatar Aug 20 '24 17:08 awschmeder