에러 관리

vscode에서 commandline으로 run 할때 DEBUG 하기

ddangchong_mom 2023. 6. 22. 17:28

1. commandline으로 run할때 launch.json에 아래와 같이 써준다.

{
    // 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",
    "configurations": [
        {
            "name": "Attach",
            "type": "python",
            "request": "attach",
            "connect" :{
                "host" : "localhost",
                "port": 7000
            }
        }
    ]
}

2. train.py 에 아래와 같이 port 번호 맞춰 적어준 다음 원래 사용하던 commandline을 run 한다.

import debugpy
debugpy.listen(7000)
print("Wait for debugger...")
debugpy.wait_for_client()
print("Debugger attached")

3. vscode의 run&debug에 attach 가 만들어져 있을 것이다. console에 wait for debugger 라고 나오면 attach 버튼을 누른다.

 

참고 : https://github.com/zhijian-liu/torchpack/issues/7

 

How to debug code launched with torchpack? · Issue #7 · zhijian-liu/torchpack

How to debug code launched with torchpack in IDE such as VSCode? Thx.

github.com