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
来跟踪函数
因此它们会相互冲突,无法同时使用