您现在的位置是:首页 >技术交流 >vscode debug Attach mode网站首页技术交流
vscode debug Attach mode
简介vscode debug Attach mode
- Python Debug Mode: 常规debug。针对*.py python脚本启动的场景。
在使用vscode debug时,如果调试python脚本其实很简单。
.vscode/launch.json文件。
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"justMyCode": false,
"program": "main.py",
"args": ["--seed", "0", "--work-dir", "./work_dir"],
}
]
}
- Python Attach Mode: 针对shell scrpt或者服务调试python脚本的场景。
比如使用torchpack启动的分布式python任务
需要用到vscode的Attach Mode
1. 配置launch.json
.vscode/launch.json文件
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5578
}
}
]
}
2. 在python代码中加入debugpy代码段
import debugpy
debugpy.listen(5678)
print("Wait for Debugger...")
debugpy.wait_for_client()
print("Debugger Attached")
# main
3. 在vscode代码中加入断点breakpoint
4. 在terminal中跑分布式任务
torchpack dist-run -np 1 python main.py
5. 在vscode中点击debug按钮,可以单步了。

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。





U8W/U8W-Mini使用与常见问题解决
QT多线程的5种用法,通过使用线程解决UI主界面的耗时操作代码,防止界面卡死。...
stm32使用HAL库配置串口中断收发数据(保姆级教程)
分享几个国内免费的ChatGPT镜像网址(亲测有效)
Allegro16.6差分等长设置及走线总结