Skip to content

Commit 73c0bd6

Browse files
committed
Close all plot windows of a blocking show() on Ctrl+C
Addresses the Qt part of #23385. It appears that `qapp.quit()` does not automatically close the windows of the app. We therefore do it explicitly. A unit test for this would be quite complex. Test this by hand by Ctrl+C in an interactive shell.
1 parent 1d1171f commit 73c0bd6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/matplotlib/backends/qt_compat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _exec(obj):
163163

164164

165165
@contextlib.contextmanager
166-
def _maybe_allow_interrupt(qapp):
166+
def _maybe_allow_interrupt(qapp_or_eventloop):
167167
"""
168168
This manager allows to terminate a plot by sending a SIGINT. It is
169169
necessary because the running Qt backend prevents Python interpreter to
@@ -215,7 +215,9 @@ def _may_clear_sock(*args):
215215
def handle(*args):
216216
nonlocal handler_args
217217
handler_args = args
218-
qapp.quit()
218+
if hasattr(qapp_or_eventloop, 'closeAllWindows'):
219+
qapp_or_eventloop.closeAllWindows()
220+
qapp_or_eventloop.quit()
219221

220222
signal.signal(signal.SIGINT, handle)
221223
try:

0 commit comments

Comments
 (0)