卡在等待预启动任务 [英] Stuck waiting for prelaunch task

查看:42
本文介绍了卡在等待预启动任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的调试环境作为 Poetry 会话运行,以便我可以正确调试封装.

I'm trying to run my debug environment as a Poetry session, so I can properly debug encapsulated.

所以,我的 launch.json 很简单:

So, my launch.json is straightforward:

        {
            "name": "Poetry",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5710
            },
            "preLaunchTask": "poetryDebugSession",
            "localRoot": "${workspaceFolder}"
        }

并且我调整了我的 tasks.json 以尝试首先在 Poetry 中启动 debugpy(如果我在终端中手动运行一些代码,这会起作用)

and I adapted my tasks.json to try to launch debugpy in Poetry first (this works if I manually run some code in the terminal)

{
            "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 任务标记为就绪":

When I start debugging, the task is properly launched, and debugpy gets all the way to the message I am waiting for that I want the preluanch task to be marked as "ready":

> 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} 在我的输出中包含完整路径,但这可能无关紧要.

I could have sworn I had this working last week but as of 1.58.2 after a restart this morning it doesn't progress past wait_for_client() display, so the debugger never attaches. I'm also a little suspicious that ${relativeFile} includes a full path in my output but that probably doesn't matter.

从上面的代码应该可以清楚地看出,我从 https://stackoverflow.com/a/54017304/1877527 ,但仍然没有骰子.

It should be clear from the code above that I derived my initial implementation from https://stackoverflow.com/a/54017304/1877527 , but still no dice.

推荐答案

debugpy 团队帮我找到了答案:

The debugpy team helped me find an answer:

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

It worked for me even without the python argument, since my primary dev machine just has one active Python installation.

这篇关于卡在等待预启动任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆