keyboard interrupt with with python gtk? keyboard interrupt with with python gtk? python python

keyboard interrupt with with python gtk?


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:

if __name__ == '__main__':    import signal    signal.signal(signal.SIGINT, signal.SIG_DFL)    your_application_main()


The accepted answer would not work for me. I resolved it by replacing the Gtk.main() call with GLib.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:

def main():    self.mainloop = GObject.MainLoop()    try:        self.mainloop.run()    except KeyboardInterrupt:        logger.info('Ctrl+C hit, quitting')        self.exit()def exit():    self.mainloop.quit()