首页 > 解决方案 > Visual Studio Code Python 调试“发生异常 SystemExit”

问题描述

很长时间以来,我一直在使用 Visual Studio 代码和 Python 扩展。

目前我有 Visual Studio Code 版本 1.27.2、Python 扩展“ms-python.python”版本 2018.8.0、python 版本 3.6.6,由 Windows 10 1803 企业版系统托管。

与过去相比,最新版本的 Code/MS Python 在调试过程中的表现有所不同。

过去,在 Visual Studio Code 中执行以下 Python 代码不会产生任何异常:

# 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')

现在结果是执行 sys_exit(1) 指令时出现 SystemExit 异常(VSCode 截图)。

问题:有没有办法禁用此行为并返回上一个行为?

标签: python-3.xvisual-studio-code

解决方案


我在调试烧瓶应用程序时遇到了类似的情况。我的解决方法是在调试窗口底部的断点菜单中取消选中“未捕获的异常”。

在此处输入图像描述


推荐阅读