Skip to content

Question: How can I run a script with pydevd in --server mode #161

Closed

Description

@etanshaul

Goal:

Similar to ptvsd's (debugging a script file), I want to launch my script with the pydevd debugger waiting in --server mode ready to accept connections from a client.

Why:

We are working on implementing remote container debugging for JetBrains IDEs (via a 3rd party plugin). The normal connection mode for pydevd is to run the debug server in the client and make a connection back from the application (in the remote env) to the IDE. I need to reverse this model: run the application and debug server in the remote container, and then connect to it from the IDE.

What I've tried:

Running the pydevd script with --server, e.g.:
pydevd --server --port [debug_port] --file myscript.py

This appears to only run the debugger, but not the script. I can elicit a response from the debug server by setting breakpoints on the client; however, this appears to be detached from the running app (which I'm currently running separately) so I cannot hit any breakpoints. I've dug up the pydevd_attach_to_process script where I think I can run the script and then attach the debugger to it but ideally I'd be able to start the script immediately with the debugger. Hopefully this makes some sense. Happy to provide more details.

Activity

  1. etanshaul commented on Jan 29, 2020

    @etanshaul
    Author

    closing for now as it seems running the app via python pydevd.py --server .. --file [my_file] does correctly run the app with the pydevd debugger

  2. fabioz commented on Jan 29, 2020

    @fabioz
    Owner

    Hi @etanshaul, sorry about the delay in getting back to you... as you probably seen, it does create a server socket and waits for the connection. What's not currently implemented is a way to start in server mode but start running before the connection is done to the server.

    This should not be difficult to do (all the machinery is there, it's just not handled in the arguments) -- you can take a look at pydevd._enable_attach and the related test which uses: _debugger_case_wait_for_attach_impl.py for how this can be done from client code (note that it's just tweaking the parameters to the pydevd.settrace, which is the public API for that to be called from client code).

  3. etanshaul commented on Jan 29, 2020

    @etanshaul
    Author

    Thanks for the follow up @fabioz .

    What's not currently implemented is a way to start in server mode but start running before the connection is done to the server.

    This is great to know. Are there any plans / ambitions to add support for this as part of the pydevd server initialization (via a flag; e.g. --no-wait or something)? I could file a feature request (and possibly look into contributing if I find some time)

  4. fabioz commented on Jan 29, 2020

    @fabioz
    Owner

    I don't really have any plans to add that, but I do accept contributions regarding adding that support (just note that it should be accompanied by a test case so that it doesn't break in the future).

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions