From 632c41b012f93fb1cf33ff85980ce138bd278c91 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 11 Nov 2021 12:12:30 -0500 Subject: [PATCH] Backport PR #21530: Fix interrupting GTK on plain Python --- lib/matplotlib/backends/_backend_gtk.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/matplotlib/backends/_backend_gtk.py b/lib/matplotlib/backends/_backend_gtk.py index 7b0341d644fb..2b095c3bc7a9 100644 --- a/lib/matplotlib/backends/_backend_gtk.py +++ b/lib/matplotlib/backends/_backend_gtk.py @@ -169,6 +169,13 @@ def mainloop(): try: _application.run() # Quits when all added windows close. + except KeyboardInterrupt: + # Ensure all windows can process their close event from + # _shutdown_application. + context = GLib.MainContext.default() + while context.pending(): + context.iteration(True) + raise finally: # Running after quit is undefined, so create a new one next time. _application = None