Search code examples
dockervisual-studio-codedebuggingremote-debugging

Multiple python remote attach in VsCode


I have a docker-compose stack with multiple services. There is 3 containers using python : flask celeryWorker1 celeryWorker2

I'm using debugpy and Python Remote Attach from VsCode to debug, with this 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": "Python: Remote Attach",
      "type": "python",
      "request": "attach",
      "connect": { "host": "0.0.0.0", "port": 6900 },
      "pathMappings": [
        {
          "localRoot": "/path/to/celeryworker1/app",
          "remoteRoot": "/app"
        },
      ],
      "justMyCode": true
    },
  ]
}

That's working well when i debug one container. But my containers are working together and i need to put some breakpoint in all my containers.

I try to add the configuration

{
  // 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": "Python: Remote Attach",
      "type": "python",
      "request": "attach",
      "connect": { "host": "0.0.0.0", "port": 6900 },
      "pathMappings": [
        {
          "localRoot": "/path/to/celeryworker1/app",
          "remoteRoot": "/app"
        },
      ],
      "justMyCode": true
    },
    {
      "name": "Python: Remote Attach",
      "type": "python",
      "request": "attach",
      "connect": {
        "host": "0.0.0.0",
        "port": 6901
      },
      "pathMappings": [
        {
          "localRoot": "/path/to/celeryworker2/app",
          "remoteRoot": "/app"
        }
      ],
      "justMyCode": true
    },
    ...
  ]
}

I have

pydev debugger: unable to find translation for: "/path/to/celeryworker2/app/app.py" in ["/path/to/celeryworker1/app", "/path/to/celeryworker1/app"] (please revise your path mappings)


Solution

  • {
      "configurations": [
        {
          "name": "celeryworker1",
          ...
        },
        {
          "name": "celeryworker2",
          ...
        },
        ...
      ]
    }
    

    I found the solution on my own, i set 2 sames name in my configuration. Working well now when i launch both debugger.