【问题标题】:Stuck waiting for prelaunch task等待启动前任务
【发布时间】:2021-09-27 11:48:17
【问题描述】:

我正在尝试将我的调试环境作为 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} 在我的输出中包含完整路径,但这可能无关紧要。

从上面的代码中应该清楚我的初始实现是从 https://stackoverflow.com/a/54017304/1877527 派生的,但仍然没有骰子。

【问题讨论】:

    标签: visual-studio-code vscode-debugger vscode-tasks


    【解决方案1】:

    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 安装。

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 2017-09-09
      相关资源
      最近更新 更多