You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: How can I run a script with pydevd in --server mode #161
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.
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).
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)
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).
Activity
etanshaul commentedon Jan 29, 2020
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 debuggerfabioz commentedon 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_attachand the related test which uses:_debugger_case_wait_for_attach_impl.pyfor how this can be done from client code (note that it's just tweaking the parameters to thepydevd.settrace, which is the public API for that to be called from client code).etanshaul commentedon Jan 29, 2020
Thanks for the follow up @fabioz .
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-waitor something)? I could file a feature request (and possibly look into contributing if I find some time)fabioz commentedon 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).