You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code调试控制台输入命令后无法触发函数断点求助

在VS Code Debug Console中调用函数无法触发断点的解决方法

我遇到的问题:通过F5启动调试时,函数内的断点能正常触发,但在Debug Console中输入函数调用命令(比如myfunc(2,3))后,程序不会停在myfunc内的断点处。修改launch.json配置后问题仍未解决。

我的配置与代码

launch.json 配置

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "internalConsoleOptions": "openOnSessionStart",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": false
        },
        {
            "name": "Python Debugger: Python File",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}"
        }
    ]
}

测试代码

def myfunc(a,b):
    s = a + b  # 此处设置断点
    return s
print(myfunc(2,3))
    
input("Press Enter to continue debug (or Ctrl+C to exit)...")

Debug Console 输出

myfunc(2,3)

5

预期效果

在Debug Console输入myfunc(2,3)后,程序停在s = a + b行的断点处。

解决步骤

  • 优先使用debugpy类型的调试配置,旧的python类型配置对Debug Console的交互式断点支持不足。
  • 修改debugpy配置项,补充以下参数:
    "console": "integratedTerminal",
    "justMyCode": false,
    "redirectOutput": true
    
    修改后的完整debugpy配置:
    {
        "name": "Python Debugger: Python File",
        "type": "debugpy",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "justMyCode": false,
        "redirectOutput": true
    }
    
  • 启动调试时选择这个更新后的debugpy配置,等程序运行到input()暂停时,切换到Debug Console输入函数调用命令,此时断点会正常触发。
  • 关键注意点:只有当程序处于暂停状态(比如卡在输入等待、手动点击暂停按钮)时,Debug Console中的交互式函数调用才会触发断点。

内容的提问来源于stack exchange,提问作者Martin Horst

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 13:21:08