【发布时间】:2019-02-21 16:15:39
【问题描述】:
我长期以来一直使用 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 screenshot)。
问题:有没有办法禁用此行为并返回上一个行为?
【问题讨论】:
-
我查看了 VS Code 源代码,这对他们来说应该很容易实现。他们在 Visual Studio Code 中内置了此功能,您可以将调试器配置为忽略特定的异常类型。
-
我在这里向 VS Code 项目提出了功能请求:github.com/microsoft/vscode/issues/91822。请看一下。
-
注意:理论上,'unreachable code' print 语句应该是不可访问的,因为根据定义, sys.exit() 应该是代码的硬退出,并且不应运行更多行。跨度>
-
这是真正的问题。请点赞。它仍然开放:github.com/microsoft/vscode-python/issues/850
标签: python-3.x visual-studio-code