So just like the question says, I'm trying to let keyboard interrupts happens while Gtk.main() is in progress, however, it just doesn't seem to notice that the keyboard interrupt happens until after the function is done.
So I tried sticking Gtk.main() in a separate thread, and have the main thread find the keyboard interupts, and terminate the thread, but then found out that Gtk doesn't play nicely with threads as described in this article
I can't think of any other way to let keyboard interrupts work. Is this possible?
I'm using python3, and want my program to eventually be cross platform.
because of https://bugzilla.gnome.org/show_bug.cgi?id=622084 gtk applications written using pygobject will not close themselves when using Ctrl + C on the terminal.
to work around it, you can install a Unix signal handler like this:
The accepted answer would not work for me. I resolved it by replacing the
Gtk.main()
call withGLib.MainLoop().run()
, as explained in the bug report.I also ran into trouble when using the signal module to override the SIGINT handler (100% CPU on the python thread); an alternative for me was the following: