卡在等待启动前任务
Stuck waiting for prelaunch task
我正在尝试 运行 我的调试环境作为 Poetry 会话,这样我就可以正确调试封装了。
所以,我的 launch.json
很简单:
{
"name": "Poetry",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5710
},
"preLaunchTask": "poetryDebugSession",
"localRoot": "${workspaceFolder}"
}
并且我调整了我的 tasks.json
以尝试首先在 Poetry 中启动 debugpy
(如果我在终端中手动 运行 一些代码,这会起作用)
{
"label": "poetryDebugSession",
"type": "shell",
"command": "poetry",
"args": [
"run",
"python",
"-m",
"debugpy",
"--log-to-stderr",
"--wait-for-client",
"--listen",
"5710",
"${relativeFile}",
"&"
],
"presentation": {
"panel": "dedicated",
"clear": true
},
"group": "test",
"isBackground": true,
"runOptions":{
"instanceLimit": 1
},
// This task is run before the launch.json task. Since it needs to run in the
// background and not wait for completion, though, we need to jump through hoops
"problemMatcher": [
{
"owner": "python",
"fileLocation": "absolute",
"pattern": [
{
"regexp": "^\s+File \"(.*)\", line (\d+), in (.*)$",
"file": 1,
"line": 2
},
{
"regexp": "^\s+(.*)$",
"message": 1
}
],
"background": {
"activeOnStart": true,
"beginsPattern": "^D[0-9\.: \+]+wait_for_client",
"endsPattern": ".*",
}
}
]
}
当我开始调试时,任务正确启动,并且 debugpy 一直到我正在等待的消息,我希望 preluanch 任务被标记为“就绪”:
> Executing task: poetry run python -m debugpy --log-to-stderr --wait-for-client --listen 5710 d:\path\to\myfile.py <
# stuff
I+00000.344: pydevd is connected to adapter at 127.0.0.1:61443
D+00000.344: wait_for_client()
我本可以 宣誓 我上周已经开始工作了,但是从今天早上重启后的 1.58.2 开始,它没有超过 wait_for_client()
显示,所以调试器永远不会附加。我也有点怀疑 ${relativeFile}
在我的输出中包含完整路径,但这可能无关紧要。
从上面的代码可以清楚地看出,我的初始实现是从 派生的,但仍然没有骰子。
debugpy
团队帮助我找到了答案:
https://github.com/microsoft/debugpy/issues/676#issuecomment-886041838
{
"name": "Python: Poetry current file",
"type": "python",
"request": "launch",
"program": "${env:USERPROFILE}/.poetry/bin/poetry",
"python": "<path/to/bare/bones/python>",
"args": ["run", "python", "${file}"],
"console": "integratedTerminal",
}
即使没有 python
参数,它也对我有用,因为我的主要开发机器只有一个活动的 Python 安装。
我正在尝试 运行 我的调试环境作为 Poetry 会话,这样我就可以正确调试封装了。
所以,我的 launch.json
很简单:
{
"name": "Poetry",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5710
},
"preLaunchTask": "poetryDebugSession",
"localRoot": "${workspaceFolder}"
}
并且我调整了我的 tasks.json
以尝试首先在 Poetry 中启动 debugpy
(如果我在终端中手动 运行 一些代码,这会起作用)
{
"label": "poetryDebugSession",
"type": "shell",
"command": "poetry",
"args": [
"run",
"python",
"-m",
"debugpy",
"--log-to-stderr",
"--wait-for-client",
"--listen",
"5710",
"${relativeFile}",
"&"
],
"presentation": {
"panel": "dedicated",
"clear": true
},
"group": "test",
"isBackground": true,
"runOptions":{
"instanceLimit": 1
},
// This task is run before the launch.json task. Since it needs to run in the
// background and not wait for completion, though, we need to jump through hoops
"problemMatcher": [
{
"owner": "python",
"fileLocation": "absolute",
"pattern": [
{
"regexp": "^\s+File \"(.*)\", line (\d+), in (.*)$",
"file": 1,
"line": 2
},
{
"regexp": "^\s+(.*)$",
"message": 1
}
],
"background": {
"activeOnStart": true,
"beginsPattern": "^D[0-9\.: \+]+wait_for_client",
"endsPattern": ".*",
}
}
]
}
当我开始调试时,任务正确启动,并且 debugpy 一直到我正在等待的消息,我希望 preluanch 任务被标记为“就绪”:
> Executing task: poetry run python -m debugpy --log-to-stderr --wait-for-client --listen 5710 d:\path\to\myfile.py <
# stuff
I+00000.344: pydevd is connected to adapter at 127.0.0.1:61443
D+00000.344: wait_for_client()
我本可以 宣誓 我上周已经开始工作了,但是从今天早上重启后的 1.58.2 开始,它没有超过 wait_for_client()
显示,所以调试器永远不会附加。我也有点怀疑 ${relativeFile}
在我的输出中包含完整路径,但这可能无关紧要。
从上面的代码可以清楚地看出,我的初始实现是从
debugpy
团队帮助我找到了答案:
https://github.com/microsoft/debugpy/issues/676#issuecomment-886041838
{
"name": "Python: Poetry current file",
"type": "python",
"request": "launch",
"program": "${env:USERPROFILE}/.poetry/bin/poetry",
"python": "<path/to/bare/bones/python>",
"args": ["run", "python", "${file}"],
"console": "integratedTerminal",
}
即使没有 python
参数,它也对我有用,因为我的主要开发机器只有一个活动的 Python 安装。