Python 代码远程调试

debugpy

纯 Python 脚本启动的程序,理论上可以直接 Python Debugger 调试

如果要附加进程的方式,在 VSCode 里实操下来,没能发现可以附加的 Python 进程

这时,只能通过 debugpy 来远程调试

参考官方例子,即可实现调试: https://code.visualstudio.com/docs/python/debugging#_example

VSCode 一键附加多个进程

在 VSCode 里,可以使用 Compound 来创建多个进程

如下:

{
    // 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",
    "compounds": [
        {
            "name": "Compound",
            "configurations": [
                "Attach Game0",
                "Attach Game1",
                "Attach Game2",
            ]
        }
    ],
    "configurations": [
        {
            "name": "Attach Game0",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "127.0.0.1",
                "port": 15670
            }
        },
        {
            "name": "Attach Game1",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "127.0.0.1",
                "port": 15671
            }
        },
        {
            "name": "Attach Game2",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "127.0.0.1",
                "port": 15672
            }
        }
    ]
}

代码覆盖率

代码覆盖率的 Python 产品,如 coveragepy 实现原理和 debugpy 类似,都是通过 sys.settrace 来跟踪函数

因此它们会相互冲突,无法同时使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fananchong2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值