Visual Studio Code Python debugging "Exception has occurred SystemExit"

Viewed 20529

I've been using Visual Studio code for a long time with the Python extension.

Currently I have Visual Studio Code version 1.27.2, Python extension "ms-python.python" version 2018.8.0, python version 3.6.6, hosted by a Windows 10 1803 Enterprise Edition system.

Compared to the past, the latest version of Code / MS Python behaves differently in the debugging process.

In the past the execution of the following Python code, within Visual Studio Code, would not have generated any exceptions:

# Import exit from sys
from sys import exit as sys_exit
# Exit to system with errorlevel set to 1
sys_exit(1)
# Next instruction is never executed.
# Executing the script directly from the terminal in Windows sets the
# errorlevel to 1 and the script execution is terminated. 
print('unreachable code')

Now the result is a SystemExit exception when sys_exit(1) instruction is executed (VSCode screenshot).

Question: is there a way to disable this behavior and return to the previous one?

2 Answers

I ran into something similar while debugging my flask application. My work-around was to uncheck "Uncaught Exceptions" in the breakpoint menu at the bottom of the debug window.

enter image description here

sys.exit can have a parameter. If you don't give it one it returns None. If anything besides 0 is returned its considered an error exit. So using this works

sys.exit(0)
Related