自分用メモ

プログラミングとかのメモを書きたいです

VSCode+Pythonのリモートデバッグ:その2

下記で書いたptvsdよりも簡単な方法があった。ソースコード側への修正は不要になる。 VSCode+Pythonのリモートデバッグ - 自分用メモ

使うもの

github.com

使い方

使い方はptvsdと似ている。 python実行するとデバッガが接続しにくるまで待つので、VScodeのデバッガで接続しにいく。

①プログラムを起動時に下記のようなオプションをつける。

python3 -m debugpy --listen localhost:5678 --wait-for-client hogehoge.py

VSCodeでリモートアタッチする

前回と同じでOK。launch.jsonは下記のような感じ。

{
    // IntelliSense を使用して利用可能な属性を学べます。
    // 既存の属性の説明をホバーして表示します。
    // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: アタッチ",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "${workspaceFolder}",
                }
            ]
        }
    ]
}