![](/img/trans.png)
[英]Visual Studio Code Django debugging breakpoints not triggered on Views and Templates
[英]Conditional breakpoints in Visual Studio Code
我在同一目录中有以下两个 python 文件:
主文件
from module import f1
f1()
模块.py
import traceback
def f1():
print('f1')
print(traceback.extract_stack()[-1].filename)
print(traceback.extract_stack()[-2].filename)
f2()
def f2():
print('f2')
print(traceback.extract_stack()[-1].filename)
print(traceback.extract_stack()[-2].filename)
我在目录中启动 VSCode 并使用以下表达式设置条件断点:
traceback.extract_stack()[-2].filename != traceback.extract_stack()[-1].filename
在f1
和f2
的第一个print
语句上。
main.py 的运行打印出来:
f1
c:\Users\...\tmp\pythonTest-breakpoint\module.py
c:\Users\...\tmp\pythonTest-breakpoint\main.py
f2
c:\Users\...\tmp\pythonTest-breakpoint\module.py
c:\Users\...\tmp\pythonTest-breakpoint\module.py
两个断点都被触发。
为什么 f2 中的断点被触发而条件不满足?
从vscode 中的教程调试中,它说:
表达式条件:只要表达式计算为真,就会触发断点。
表达式的值决定了在当前断点调试时代码是暂停还是跳过,对代码 output 没有影响。
至于您的问题,您认为print("f2")
处表达式的值是假的,但事实是断点机制将其视为真,因此触发了断点:
我也把表达式的值改成了False ,f2()的断点也被触发了,所以vscode中的条件断点可能有问题导致了这种现象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.