-
Notifications
You must be signed in to change notification settings - Fork 137
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
[Investigate] Remote attach without launching adapter subprocess #532
Comments
0.0.0.0 means "listen on all known interfaces on the specified port". But when connecting, you need to specify the specific address to connect to - I'm not even sure what 0.0.0.0 is supposed to mean when it's used for a client socket, but it can't be right. If you're connecting to 3DS Max instance that's running on the same machine as VSCode, you should be using 127.0.0.1 on both sides. Also note that listening on 0.0.0.0 means that anybody who can connect to your machine over the network to the port it's listening on, can debug it - unless you're on a private secure network, you really don't want to do that, because the debugger allows execution of arbitrary code (via e.g. Watch). |
Thanks for the reply @int19h VSCode and the instance of Max are on the same machine - thankfully we are on a private secure network. Thanks for the information though, that is good to know. Stacktrace from within Max2018:
Supporting Py27 is a pain, unfortunately we are stuck with it due to the software we use having it as it's embedded version. |
Listening on 0.0.0.0 is fine (security aside), it's connecting that has unclear semantics. It should be okay to listen on 0.0.0.0, but connect to 127.0.0.1. In your case, since it's all local, 127.0.0.1 is the right choice for both ends. It is also the default if you specify the port, but omit the host. |
Can you double-check that the version of Python interpreter that you're passing to If that's the case, then we'll need logs to figure out what's going on here. You can get those by doing:
The resulting log files will be named |
The standalone interpreter is a studio distribution of Python37, which has debugpy installed on it. Thanks again for the help. |
Here is the log file generated from within 3DsMax 2018: |
The most interesting log in this case is the one that comes from the adapter, but it looks like it didn't even get to the point where it started logging. But it might be possible to diagnose this manually by replicating what the server is trying to do; specifically:
Can you try running this same thing manually in the terminal, and see what errors (if any) it produces? |
So if I run debugpy in our Python27 venv it seems to work correctly: C:\P4\Tools\Python\environment\2.7\Scripts\activate It seems to work without issue and generates two log files: |
Interesting. Sounds like Python version mismatch is a problem in this scenario. This is unexpected, and I'll take a look at what breaks there, but for now, I guess this is the workaround. Thank you for your help in diagnosing this! |
Ah - that is good that you have spotted an issue! |
I'm having similar problems with Kodi on macos. Why does debugpy have to spawn? it would be very nice if it supported a non-spawn mode to make life simpler. I just want to set a set_trace(). Kodi on macos doesn't have a command line interpreter as far as I can tell. It's embedded.
Note Config is
And no adapter log generated If I run the adapter command line manually it seems to work fine
|
I was able to get it to work by having the external Python interpreter match the version of the embedded version:
|
@djay It has to spawn because some things that debugger needs to do, cannot be done reasonably well from within the same process that is being debugged. The older versions (pre-ptvsd 5.x) didn't have a multiproc architecture, and there was a slew of bugs and limitations stemming from that. And, unfortunately, it's a fairly fundamental architectural decision, so we can't easily support a "no-spawn mode" or something like that for debugpy. Although it might be possible to use pydevd as a standalone DAP server at this point - it might be fully compatible with VSCode by now even without debugpy in the picture. @fabioz, can you advise? Also note that you don't need the interpreter offered by the app doing the embedding. You just need some Python interpreter, somewhere. As @RockShea noted above, at the moment, it seems to only work correctly if the language version matches (although that wasn't intended). So, you just need to install a matching version of Python, and then use |
@int19h I'm not sure the language version is the problem in this case. how close do they have to be? |
@djay When the adapter is spawned, it does adjust PYTHONPATH so that it can import other modules from itself. However, this should not be affecting anything from stdlib: debugpy/src/debugpy/adapter/__main__.py Lines 191 to 217 in cbcfe22
What's particularly interesting about your error is that it complains about The other thing is, the error seems to be happening very early in the adapter process - before it gets a chance to do anything, really; this is literally the first executable line of its One thing that might help diagnose it is manually logging some information early on in that |
It's using the homebrew python I specified but with the paths of the embedded python. But I guess because kodis python is embedded it can't get hold of those internal modules like _collections. Shouldn't the paths also include paths from the python I specify? |
If I manipulate the path to put in some of the paths from my system python then it works. The path it needed was '/usr/local/Cellar/python@2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload' |
@int19h (it seems I missed that message, sorry for the delay)... the auto-attach to subprocess wouldn't work, but apart from that it should be possible to get that working (although I haven't really tested connecting directly to VSCode, it's something that I think would be reasonably straightforward, especially when connecting to applications that have Python builtin as spawning a Python subprocess isn't always easy in such cases as mismatches aren't that uncommon due to misconfigurations -- still, it needs some testing on my side to make sure it actually works as I expect it to). |
I've done some experiments here and with a few changes it is possible to debug using the process itself without spawning a separate debug adapter process (so the connection is managed directly by pydevd). For the API I was thinking about:
Other ideas on a better API/naming are welcome. I think it should be even possible to support launching new subprocesses by sending the Thoughts @rchiodo @int19h @karthiknadig? |
I wonder if this would be better exposed as a public pydevd API? debugpy isn't really doing anything useful in this scenario. For the web, we'll need some custom wrapper anyway to set up the environment and handle DAP "launch", so it would also transparently call this API then. |
I think it boils down to whether we'd like to keep i.e.: it may not make much difference in the web case, but on cases where the user has issues on getting a python executable just for the debug adapter process it may be a better API since users are expecting to interact with -- also, a plain |
The basic listen mode without an additional adapter is working (in #1050) and I was checking how to implement the auto attach to subprocesses in this case. After playing with it a bit, I must say that the only I can see it working on all cases would be spawning a secondary process to handle it (otherwise cases such as Linux where the user uses some API which replaces the current process don't work because we need to ask for the connection to be done in the original process, but the child process replaces the original process prior to that) -- but then, this has no advantage over just using Still, this is only a problem because we're doing a listen in the debugger side. If the connection was done the other way around (i.e.: if VSCode opens a server socket and starts debugging any incoming connection) then this use-case would work out of the box (so, we'd add the So, my question is how to proceed given that. The options I can see are:
What do you think @rchiodo @int19h @karthiknadig? |
For this scenario as well as the web one, subprocesses are not really in the picture, so I think we should proceed with the last approach. |
Seems good to me... I just need to do a couple of fixes in the PR then (don't monkey-patch subprocess in this scenario and update some docs there -- I'll probably merge on Thursday). |
This is fixed (in 30a96bf). |
Environment data
Actual behavior
Remote attach times out from 3DsMax 2018 - which runs embedded Python27.
Here is the stacktrace, from 3DsMax 2018:
And the error message in VSCode:
Expected behavior
Remote attach to correctly connect, as it does with 3DsMax 2021 - which runs embedded Python 37.
Steps to reproduce:
VSCode config settings which work in 3DsMax 2021 - Python37, but not 3DsMax 2018 - Python27:
Code to run within 3DsMax, which works in 2021 - Python37 and not 2018 - Python27:
The text was updated successfully, but these errors were encountered: