diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index b36e6564287b..181dcb4843f7 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -1091,9 +1091,11 @@ def trigger_manager_draw(manager): def mainloop(): old_signal = signal.getsignal(signal.SIGINT) # allow SIGINT exceptions to close the plot window. - signal.signal(signal.SIGINT, signal.SIG_DFL) + if old_signal: + signal.signal(signal.SIGINT, signal.SIG_DFL) try: qApp.exec_() finally: # reset the SIGINT exception handler - signal.signal(signal.SIGINT, old_signal) + if old_signal: + signal.signal(signal.SIGINT, old_signal)