1

I want to capture Ctrl+C in my Python code in Visual Studio Code. In both integrated and external consoles, Ctrl+C results in "forrtl: error (200): program aborting due to control-C event" and my try-except statement doesn't catch the interrupt. The code is in this form:

def main():
    try:
        somecode
    except KeyboardInterrupt:
        somecode
L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57
  • I think it isn't a vscode problem. I tested with python 2.7 and 3.5 and it works. See [this](https://stackoverflow.com/questions/1112343/how-do-i-capture-sigint-in-python) and [this](https://stackoverflow.com/questions/15457786/ctrl-c-crashes-python-after-importing-scipy-stats) – 4ndt3s Mar 12 '18 at 23:12
  • Agreed, I too have tried the above code and it works as expected. You might want to try changing your code (`somecode`) into a loop and testing this without any external dependencies. – Don Mar 18 '18 at 04:58
  • I tried both referenced methods and everything (even my own implementation) works on simple code, but in my actual, which consists of multiple classes and `somecode` uses different methods of these classes, it doesn't work and results in **forrtl: error (200)...**. – Sadjad Anzabi Zadeh Mar 18 '18 at 23:01

0 Answers0