13

I'm trying to do the exact same thing as this question:

How to prevent a block of code from being interrupted by KeyboardInterrupt in Python? (sorry, not enough rep yet to post this as a comment there)

However both of the top answers posted there aren't working for me. When I hit CTRL+C with either of those solutions in place, the script still closes immediately with:

forrtl: error (200): program aborting due to control-C event

The code I'm working on is fairly long and includes quite a few imported modules. Am I correct to assume one of these modules is interfering with the normal behavior of KeyboardInterrupt? If so, how can I figure out which one?

(I'm running python 2.7.6, 32bit on Windows)

thanks.

Community
  • 1
  • 1
tfg250
  • 416
  • 3
  • 10

2 Answers2

7

Scipy was causing the problem. The link below provides a solution, note that this is not unique to scipy.stats, but also occurs with other scipy functions.

Ctrl-C crashes Python after importing scipy.stats

Community
  • 1
  • 1
tfg250
  • 416
  • 3
  • 10
  • 4 weeks of debugging, now I learnt its the stupid from `scipy.signal import savgol_filter`. Found more elegant solution than the stuff in the link: just put the `scipy` import inside a function and that would make your `main` safe enogh. – Alex Deft Dec 09 '21 at 18:54
0

A part from those specific cases above (question and above answer), for those of you still stuck in this

forrtl: error (200): program aborting due to control-C event

trying to obtain a normal behaviour of CTRL+C KeyboardInterrupt during the execution of a program (in my case it's a training procedure of neural network model with PyTorch executed within PyCharm IDE on Windows 10 and anaconda python3.8).

It turned out to be a problem of corrupted anaconda environment or either some package within. For me, reinstalling the previous version of PyCharm (downgrading from 2022 to 2021) and replacing the old environment with a brand new one, solved the problem. The KeyboardInterrupt turned back to its old useful behaviour, stopping the program but not exiting the python console at CTRL+C event.

Hope it helped someone.