gpt4 book ai didi

python - 调试期间 VSCode python 'Unverified breakpoint'?

转载 作者:太空宇宙 更新时间:2023-11-04 07:54:32 25 4
gpt4 key购买 nike

我正在使用 VSCode 调试我的 Python 应用程序。

我有一个主要的 python 文件,我从那里启动调试器。我可以在此文件中放置断点,但如果我想在主文件调用的其他文件中放置断点,我将它们作为“未验证断点”获取,调试器将忽略它们。

如何更改我的 launch.json 以便我能够在项目中的所有文件上放置断点?

这是我当前的 launch.json:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}"
},
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"port": 3000,
"secret": "my_secret",
"host": "localhost"
},
{
"name": "Python: Terminal (integrated)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Terminal (external)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"debugOptions": [
"RedirectOutput",
"Django"
]
},
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "${workspaceFolder}/app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
]
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "nf.session.session"
},
{
"name": "Python: Pyramid",
"type": "python",
"request": "launch",
"args": [
"${workspaceFolder}/development.ini"
],
"debugOptions": [
"RedirectOutput",
"Pyramid"
]
},
{
"name": "Python: Watson",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/console.py",
"args": [
"dev",
"runserver",
"--noreload=True"
]
},
{
"name": "Python: All debug Options",
"type": "python",
"request": "launch",
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"module": "module.name",
"env": {
"VAR1": "1",
"VAR2": "2"
},
"envFile": "${workspaceFolder}/.env",
"args": [
"arg1",
"arg2"
],
"debugOptions": [
"RedirectOutput"
]
}
]
}

谢谢

最佳答案

这可能是“justMyCode”配置选项的结果,因为它默认为 true。

虽然提供者的描述是“...仅对用户编写的代码进行调试。设置为 False 还可以启用对标准库函数的调试。”,我认为他们的意思是站点包中的任何内容对于当前的python环境不会调试。

我想调试 Django 堆栈以确定源 self 的代码的异常在何处被吞噬而不浮出水面,因此我对 VSCode 调试器的启动配置执行了此操作:

   {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Control Center",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload"
],
"justMyCode": false, // I want to debug through Django framework code sometimes
"django": true
}
]
}

我一这样做,调试器就删除了“未验证断点”消息,并允许我调试我正在处理的虚拟环境的站点包中的文件,其中包含 Django。

我应该注意到,调试器的断点部分给了我关于为什么断点未被验证以及对启动配置进行哪些调整的提示:

Breakpoints section of VSCode Debugger with useful tip

另外一个注意事项:“--noreload”参数也很重要。在使用 Flask 调试不同的应用程序时,调试器不会在任何断点处停止,直到我将它添加到启动配置中。

关于python - 调试期间 VSCode python 'Unverified breakpoint'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50601935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com