Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom handler for KeyboardInterrupt #205

Open
jabbson opened this issue Jul 18, 2023 · 3 comments
Open

Custom handler for KeyboardInterrupt #205

jabbson opened this issue Jul 18, 2023 · 3 comments

Comments

@jabbson
Copy link

jabbson commented Jul 18, 2023

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?

@porovaara
Copy link

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
Copy link

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

@awschmeder
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants