使用VS代码时,__ debug__始终设置为True

时间:2019-07-16 04:34:38

标签: python vscode-debugger

在使用VS代码调试软件时尝试给我的程序提供模拟数据,并希望为此使用内置的 debug ,但出于某些原因,它始终设置为true。

我可以在没有VS代码的情况下使用python.exe的“ -O”参数来工作,但是由于某种原因,这不是调试在VS代码中工作的方式。

debug.py:

print(__debug__)

在vs代码中按F5键的命令(调试)

C:\python>cd c:\python && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && C:\ProgramData\Anaconda2\python.exe c:\Users\name\.vscode\extensions\ms-python.python-2019.6.24221\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 54194 c:\python\debug.py "
True

在vs代码中按Ctrl + F5时的命令(不调试)

C:\python>cd c:\python && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && C:\ProgramData\Anaconda2\python.exe c:\Users\name\.vscode\extensions\ms-python.python-2019.6.24221\pythonFiles\ptvsd_launcher.py --default --nodebug --client --host localhost --port 54196 c:\python\debug.py "
True
(base) C:\python>python debug.py
True
(base) C:\python>python debug.py -O
True
(base) C:\python>python -O debug.py
False

因此,当在.py文件之前添加-O时,它可以工作。如果我将以下内容添加到launch.json:

"args": ["-O"]

它将终止在命令的末尾,仅在“ debug.py”之后,因此按照上面的示例,它不会起作用。我看到VS Code正在使用--nodebug而不是-O,这似乎也没有任何效果。应该如何运作?不太确定VSCode的ptvsd_launcher.py如何工作吗?如何在VS Code中使CTRL + F5设置为 debug = True?

0 个答案:

没有答案