一、修改launch.json(VSCode)
| { |
| |
| |
| |
| "version": "0.2.0", |
| "configurations": [ |
| { |
| "name": "Python: Current File", |
| "type": "python", |
| "request": "launch", |
| "program": "${file}", |
| "console": "integratedTerminal", |
| "justMyCode": true |
| } |
| ] |
| } |
复制
注销掉代码:
| // "program": "${file}", |
| // "console": "integratedTerminal", |
复制
添加代码:
| "connect": { |
| "host": "localhost", |
| "port": 50678 |
| } |
复制
| { |
| // 使用 IntelliSense 了解相关属性。 |
| // 悬停以查看现有属性的描述。 |
| // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 |
| "version": "0.2.0", |
| "configurations": [ |
| { |
| "name": "Python: Current File", |
| "type": "debugpy", |
| "request": "attach", |
| // "program": "${file}", |
| // "console": "integratedTerminal", |
| "justMyCode": false, |
| "connect": { |
| "host": "localhost", |
| "port": 50678 |
| } |
| } |
| ] |
| } |
复制
二、train.sh
利用debugpy调试,设定调试用的GPU标号为2
| #!/usr/bin/env bash |
| |
| |
| export CUDA_VISIBLE_DEVICES=2,3 |
| python3 -m debugpy --listen 50678 --wait-for-client train.py |
复制
三、在vscode的terminal运行:
复制
运行完成shell脚本后停在python脚本调用的入口,点击F5进入python调试。