8000 Fix interrupting GTK on plain Python · matplotlib/matplotlib@9277681 · GitHub
[go: up one dir, main page]

Skip to content < 8000 div data-target="react-partial.reactRoot">

Commit 9277681

Browse files
committed
Fix interrupting GTK on plain Python
When the application is shut down, it's intended that all windows are closed. This shutdown event is also run if interrupted with Ctrl-C. But then the main loop is no longer running, and windows do not notice the close event sent to them. In IPython, the input hook runs the loop and allows the windows to close down. But in plain Python, there is no input hook integration, and the windows sit around in limbo without accepting any events. Absent any new input hook integrations, the workaround is to iterate the main loop on interrupt.
1 parent b09aad2 commit 9277681

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/matplotlib/backends/_backend_gtk.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ def mainloop():
169169

170170
try:
171171
_application.run() # Quits when all added windows close.
172+
except KeyboardInterrupt:
173+
# Ensure all windows can process their close event from
174+
# _shutdown_application.
175+
context = GLib.MainContext.default()
176+
while context.pending():
177+
context.iteration(True)
172178
finally:
173179
# Running after quit is undefined, so create a new one next time.
174180
_application = None

0 commit comments

Comments
 (0)
0