使用 debugpy 进行远程调试可以从代码进行,但不能从命令行进行

问题描述 投票:0回答:2

我有一个 python 二进制文件(它是使用

bazel
构建的,但我认为这不相关),我可以像这样运行:

$ bazel-bin/path/to/my_test

----------------------------------------------------------------------
Ran 5 tests in 0.228s

OK

我想使用

debugpy
在 Visual Studio Code 中调试此二进制文件。我可以去我想要调试的文件并添加

import debugpy
debugpy.listen(('0.0.0.0', 5678))
debugpy.wait_for_client()

构建并运行二进制文件,它开始等待客户端,然后我使用此 vscode 配置

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "host": "127.0.0.1",
            "port": 5678,
        }
    ]
}

一切正常。我可以设置断点,跳转代码,完美。

现在,如果我不是在顶部添加代码,而是:

python3 -m debugpy --listen 0.0.0.0:5678 --wait-for-client bazel-bin/path/to/my_test

看起来客户端正在等待连接。然后我开始在 vscode 上进行远程调试......什么也没有发生。调试器在一秒钟内启动并完成。我没有看到任何日志,也没有错误。

在哪里可以找到日志来查看客户端或 vscode 发生了什么?

python debugging visual-studio-code remote-debugging
2个回答
0
投票

你添加断点了吗?

debugpy.breakpoint()

import debugpy

# 5678 is the default attach port in the VS Code debug configurations. Unless a host and port are specified, host defaults to 127.0.0.1
debugpy.listen(5678)
print("Waiting for debugger attach")
debugpy.wait_for_client()
debugpy.breakpoint() #must have
print('break on this line')

参考:https://code.visualstudio.com/docs/python/debugging


-1
投票

您可以在附加到调试服务器之前在Python源文件中放置一个断点,然后它会在附加后命中并断回VSCode。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.