Skip to content

Close all plot windows of a blocking show() on Ctrl+C #27064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _exec(obj):


@contextlib.contextmanager
def _maybe_allow_interrupt(qapp):
def _maybe_allow_interrupt(qapp_or_eventloop):
"""
This manager allows to terminate a plot by sending a SIGINT. It is
necessary because the running Qt backend prevents Python interpreter to
Expand Down Expand Up @@ -215,7 +215,9 @@ def _may_clear_sock(*args):
def handle(*args):
nonlocal handler_args
handler_args = args
qapp.quit()
if hasattr(qapp_or_eventloop, 'closeAllWindows'):
qapp_or_eventloop.closeAllWindows()
qapp_or_eventloop.quit()

signal.signal(signal.SIGINT, handle)
try:
Expand Down