In my Python script, I operate an infinite loop. I want to make sure that if I stop it, all the changes I made are reversed. Currently, I execute the script directly from the terminal, and I stop the script via Strg+C. a = 0 try: while True: a = 1 except KeyboardInterrupt: a = 0 However, I want to execute the script in PyCharm. There, I can't use Strg+C, but the "Stop" button, which will result in PyCharm returning Process finished with exit code -1. How can I catch this exception? Continue reading...