Skip to content

Instantly share code, notes, and snippets.

@djwbrown
Last active April 11, 2022 10:24
Show Gist options
  • Save djwbrown/3e24bf4e0c5e9ee156a5 to your computer and use it in GitHub Desktop.
Save djwbrown/3e24bf4e0c5e9ee156a5 to your computer and use it in GitHub Desktop.
matplotlib.pyplot blackmagic to make CTRL-C work again
import sys
import matplotlib.pyplot as plt
try:
# Put matplotlib.pyplot in interactive mode so that the plots are shown in a background thread.
plt.ion()
while(True):
plt.show()
except KeyboardInterrupt:
print ""
sys.exit(0)
@fospald
Copy link

fospald commented Apr 11, 2022

More simple solution: Add at beginning of your program

import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment