And*_*oli 12 python-3.x visual-studio-code
我使用Python扩展已经使用Visual Studio代码了很长时间.
目前我有Visual Studio代码版本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')
Run Code Online (Sandbox Code Playgroud)
现在,当执行sys_exit(1)指令时,结果是一个SystemExit异常(VSCode屏幕截图).
问题:有没有办法禁用此行为并返回上一个行为?
小智 7
sys.exit可以有一个参数。如果你不给它一个它返回 None 。如果返回 0 以外的任何内容,则将其视为错误退出。所以使用这个作品
sys.exit(0)
Run Code Online (Sandbox Code Playgroud)
在调试Flask应用程序时遇到了类似的情况。我的解决方法是在调试窗口底部的断点菜单中取消选中“未捕获的异常”。
| 归档时间: |
|
| 查看次数: |
4178 次 |
| 最近记录: |