-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install a default SIGINT handler for functions which start an event loop
Currently ctrl+c on a program blocked on Gtk.main() will raise an exception but not return control. While it's easy to set up the proper signal handling and stop the event loop or execute some other application shutdown code it's nice to have a good default behaviour for small prototypes/examples or when testing some code in an interactive console. This adds a context manager which registers a SIGINT handler only in case the default Python signal handler is active and restores the original handle afterwards. Since signal handlers registered through g_unix_signal_add() are not detected by Python's signal module we use PyOS_getsig() through ctypes to detect if the signal handler is changed from outside. In case of nested event loops, all of them will be aborted. In case an event loop is started in a thread, nothing will happen. The context manager is used in the overrides for Gtk.main(), Gtk.Dialog.run(), Gio.Application.run() and GLib.MainLoop.run() This also fixes GLib.MainLoop.run() replacing a non-default signal handler and not restoring the default one: https://bugzilla.gnome.org/show_bug.cgi?id=698623 https://bugzilla.gnome.org/show_bug.cgi?id=622084
- Loading branch information
Showing
5 changed files
with
203 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters