Skip to content

Remote debugging with debugpy #868

Closed

Description

@omri-shilton

Hello,
Is it possible to debug remote python code, such as in a kubernetes cluster?
When i'm trying to debug a local docker container im getting: "Breakpoint in file that does not exist" while setting a breakpoint.

Activity

  1. angelozerr commented on Feb 25, 2025

    @angelozerr
    Contributor

    I have never tried but if I understand correctly @scweber-cisco did that with docker.

    @omri-shilton as lsp4ij dap support is a new feature, I suggest that you try to debug python files with vscode. Once it is working´ try to configure lsp4ij dap support with the same configuration.

    In otherwise I suggest that you read https://code.visualstudio.com/docs/python/debugging

  2. omri-shilton commented on Feb 25, 2025

    @omri-shilton
    Author

    @scweber-cisco can you elaborate a bit on how you got it to work?

  3. scweber-cisco commented on Feb 25, 2025

    @scweber-cisco

    @omri-shilton without knowing specifics of your configuration, I would guess it is probably that you need to set pathMappings in your DAP parameters (JSON) field.

    Image

    I found some very light documentation here: https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings

    Depending on your configuration, you may only need one pathMappings entry, or your may need a lot. The localRoot points to a source code folder on your local development machine (where you are running PyCharm); and the remoteReoot points to the folder where the same source code lives on the remote machine where you are wanting to debug.

    Again, depending on your configuration, you may need to also set justMyCode to false.

  4. dorkwingduck commented on Mar 6, 2025

    @dorkwingduck

    @scweber-cisco Im having a similar issue with the current python-debugpy addition. In my case, I want to run debugpy while running a uvicorn server within a k8s pod, and be able to set breakpoints within an endpoint. I have configured it the way you suggested with pathMappings, however upon running it, it does not acknowledge the breakpoint. I saw in your specification that the breakpoint event isnt supported yet, however from the example documentation it seems like it should be? I was wondering if you have a working example we could reference.

  5. angelozerr commented on Mar 6, 2025

    @angelozerr
    Contributor

    @scweber-cisco Im having a similar issue with the current python-debugpy addition. In my case, I want to run debugpy while running a uvicorn server within a k8s pod, and be able to set breakpoints within an endpoint. I have configured it the way you suggested with pathMappings, however upon running it, it does not acknowledge the breakpoint. I saw in your specification that the breakpoint event isnt supported yet, however from the example documentation it seems like it should be? I was wondering if you have a working example we could reference.

    I suggest that you try with vscode to find the proper config and after that use this config with lsp4ij.

    If it doesnt work it means that there is a bug with dap support.

  6. AliakbarSu commented on Mar 6, 2025

    @AliakbarSu

    setting breakpoint using debugpy.breakpoint() in the code works with the correct pathMapping however, setting breakpoint using IDE doesn't seem to work

  7. scweber-cisco commented on Mar 6, 2025

    @scweber-cisco

    @dorkwingduck I have a working configuration, but it is highly specific to the non-public details of my repository, application, and deployment. Sharing it would not yield benefit to anyone outside of those who work in my repo. Sorry. I do think that @angelozerr 's suggestion is probably your best next step.

  8. pnovotnak commented on Mar 7, 2025

    @pnovotnak

    @AliakbarSu This definitely works. I was able to interact with a remote debugger running in k8s today via a debugger port forward. My setup is very similar to yours, and I'm even using an event loop for my service.

    Are you running your Debug Adapter Protocol configuration in debug mode? It's possible to connect to the server in "run" mode which confusingly DOES redirect output but doesn't activate breakpoints. However, I didn't see any errors when I did this, so I don't think I ever had path issues.

    Attached is a screenshot of the working configuration.

    Image

    I am able to use breakpoints without the DAP specific configuration.

    Image
  9. AliakbarSu commented on Mar 7, 2025

    @AliakbarSu

    @pnovotnak thanks! can confirm this is working in debugMode and this is my config:

    {
      "name": "Attach",
      "type": "python",
      "request": "attach",
      "redirectOutput": true,
      "justMyCode": true,
      "connect": {
        "host": "127.0.0.1",
        "port": 5678
      },
       "pathMappings": [
            {
              "localRoot": "/Users/ali/repos/workflows/BugFixes/backend",
              "remoteRoot": "/backend"
            }
          ]
    }
    
  10. angelozerr commented on Mar 8, 2025

    @angelozerr
    Contributor

    @omri-shilton can we close this issue? I think it is more a configuration problem.

  11. omri-shilton commented on Mar 9, 2025

    @omri-shilton
    Author

    i think so, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions