Ошибка при использовании кода Visual Studio для удаленной отладки кода python

#python-3.x #docker #visual-studio-code #remote-debugging

#python-3.x #docker #visual-studio-code #удаленная отладка

Вопрос:

macOS: 10.15.6 Visual Studio Code: 1.49.1

launch.json:

 {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "logToFile": true,
            "justMyCode": false,
            "outputCapture": "std",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "${workspaceFolder}"
                }
            ]
        }
    ]
}
  

Команда
Docker
docker run —name faber —rm -it
-p 0.0.0.0: 8020-8027:8020-8027 -p 8028: 8028
…….

Файл журнала кода Visual Studio

 0 Starting Session:
{
    "name": "Python: Remote Attach",
    "type": "python",
    "request": "attach",
    "logToFile": true,
    "justMyCode": false,
    "outputCapture": "std",
    "connect": {
        "host": "localhost",
        "port": 5678
    },
    "pathMappings": [
        {
            "localRoot": "/Users/j.bora/work/bsi/Blockchain/identity-and-access-management/aries-cloudagent-python",
            "remoteRoot": "/Users/j.bora/work/bsi/Blockchain/identity-and-access-management/aries-cloudagent-python"
        }
    ],
    "debugOptions": [
        "DebugStdLib",
        "RedirectOutput",
        "UnixClient",
        "ShowReturnValue"
    ],
    "showReturnValue": true,
    "workspaceFolder": "/Users/j.bora/work/bsi/Blockchain/identity-and-access-management/aries-cloudagent-python"
}
1 Client --> Adapter:
{
    "command": "initialize",
    "arguments": {
        "clientID": "vscode",
        "clientName": "Visual Studio Code",
        "adapterID": "python",
        "pathFormat": "path",
        "linesStartAt1": true,
        "columnsStartAt1": true,
        "supportsVariableType": true,
        "supportsVariablePaging": true,
        "supportsRunInTerminalRequest": true,
        "locale": "en-us",
        "supportsProgressReporting": true
    },
    "type": "request",
    "seq": 1
}
3 Error:
{}
5 Client --> Adapter:
{
    "command": "disconnect",
    "arguments": {
        "restart": false
    },
    "type": "request",
    "seq": 2
}
6 Error:
{
    "code": "EPIPE"
}
2508 Stopping Session
  

Как показано в файле журнала выше, я получаю и ошибку EPIPE. Также отладчик не подключается к удаленному процессу docker. Пожалуйста, кто-нибудь может помочь, о чем эта ошибка. Спасибо.

Ответ №1:

У меня была такая же проблема, когда я позволил отладчику прослушивать localhost внутри контейнера вместо 0.0.0.0, например:

 python -m debugpy --listen localhost:5678 myfile.py
  

Запуск его на 0.0.0.0 разрешил проблему:

 python -m debugpy --listen 0.0.0.0:5678 myfile.py