【问题标题】:VS Code Python debugger - parameter values during returnVS Code Python 调试器 - 返回期间的参数值
【发布时间】:2020-11-20 18:21:19
【问题描述】:

我正在使用 VS code 的 Python 调试器来监控函数返回。

Python: 3.7.3
VS Code:  1.51.0
Python Extension: v2020.11.371526539
MACOS: 10.15.7 (19H2)

我可以在变量返回之前检查它们,它们是正确的,但是在返回之后,它们会假定以前保存的值 - 就像它们从未被 return 语句覆盖一样。

def align_bb(self, bbs2)
    ...
    # the variables are correct  at this point 
    return update_obj, new_obj, stale_obj

#but they change by the time they come back from the function
update_obj, new_obj, stale_obj = trk.align_bb(bbs2)

函数内部的参数值

update_obj, new_obj, stale_obj
([], [[...], [...], [...]], [0])
special variables
function variables
0:[]
1:[[10, 20, 80, 100], [80, 110, 90, 110], [80, 100, 10, 40]]
2:[0]
len():3

return语句后的参数值:

update_obj, new_obj, stale_obj
([], [[...]], [])
special variables
function variables
0:[]
1:[[35, 65, 35, 65]]
2:[]
len():3

如果我在调试器之外运行代码,返回值保持一致。我已经重新启动了 VS 代码和我的计算机。我还恢复了 python 扩展并卸载了它,但我每次都得到相同的奇怪值。我肯定是在函数返回之后查看值,而不是之前。

【问题讨论】:

  • 你的代码是不是做错了,还是只是调试器显示问题?
  • 似乎仅限于调试器。如果我运行python tracker.py,返回是正确的。我也在调试控制台中获得了这些值

标签: python vscode-debugger


【解决方案1】:

我在函数的返回行有一个断点,在返回后的函数调用/赋值处有一个断点。

    def align_bb(self, bbs2)
    ...
    # the variables are correct  at this point 
    return update_obj, new_obj, stale_obj # I had a breakpoint here

update_obj, new_obj, stale_obj = trk.align_bb(bbs2) # and a breakpoint here
assert update_obj == []
#moving the breakpoint to the next line of execution fixed the issue.

移动后一个断点可以解决问题。它是可重复的——如果我把断点放回去,就会发生错误。

我想知道为什么会这样,所以我暂时没有解决这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    相关资源
    最近更新 更多