Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
etanshaul opened this issue Jan 27, 2020 · 4 comments · May be fixed by #199
Closed

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

etanshaul opened this issue Jan 27, 2020 · 4 comments · May be fixed by #199

Comments

@etanshaul
Copy link

etanshaul commented Jan 27, 2020

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.

@etanshaul
Copy link
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

@fabioz
Copy link
Owner

fabioz commented Jan 29, 2020

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).

@etanshaul
Copy link
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)

@fabioz
Copy link
Owner

fabioz commented Jan 29, 2020

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
Labels
None yet
Projects
None yet
2 participants