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

Remote Attach Times out #90

Closed
munkybutt opened this issue Sep 2, 2020 · 7 comments
Closed

Remote Attach Times out #90

munkybutt opened this issue Sep 2, 2020 · 7 comments

Comments

@munkybutt
Copy link

munkybutt commented Sep 2, 2020

Hey!

I use the debugger to remote debug 3DsMax, which runs an embedded python interpreter.
Since updating to debugpy I have been unable to run the debugger due to debugpy wanting to spawn a sub-process which doesn't really work in an embedded environment.
The main issue was described here:
microsoft/debugpy#387
microsoft/debugpy#262
And I have used the hacky work around of temporarily overwriting sys.executable before launching debugpy.
I now have an issue whereby the connection just times out and I am unable to figure out why.

This is my config in Sublime:

"debug.configurations":
[
	{
		"name": "Python: Attach to 3DsMax",
		"type": "python",
		"request": "attach",
		"connect": {
            "host": "localhost",
            "port": 3000
        },
		"python": "C:\\Python27\\python27.exe"
	}
]

and this is the code being run from within 3DsMax:

from __future__ import print_function

import sys
import debugpy


def start(inAddress=("0.0.0.0", 3000), waitForAttach=True):
	""" Start the debugger in the current python interpreter.
		This allows connection from a remote debugger, such as Sublime or VSCode.

		Args:
			inAddress (tuple, optional): Tuple of address information.
				Defaults to ("0.0.0.0", 3000).
			waitForAttach (bool, optional): If True, will block program execution
				until the debugger is attached.
				Defaults to False.

		Returns:
			bool: True on success, False on failure.
	"""

	exe = sys.executable
	try:
		# sys.executable = "C:\\Windows\\python.exe"
		sys.executable = "C:\\Python27\\python27.exe"
		debugpy.listen(inAddress)
	finally:
		sys.executable = exe

	if waitForAttach:
		debugpy.wait_for_client()


if __name__ in ("__main__", "__builtin__"):

	start(inAddress=("0.0.0.0", 3000), waitForAttach=False)

The 3DsMax Python version is 2.7 and the python version I am pointing to is also 2.7.
Both have debugpy installed.

@daniele-niero
Copy link

daniele-niero commented Sep 3, 2020

Just want to say that the same exact issue, for the same exact reason, happen for Maya.

From Visual Studio Code the debugger attaches itself without problem, of course, we have first to use "the hacky work around of temporarily overwriting sys.executable before launching debugpy" that is described in those debugpy issues that @munkybuttballs have already posted.

@munkybutt
Copy link
Author

munkybutt commented Jan 25, 2021

Hey - I have finally had a chance to follow this up after the embedded interpreter fixes went into debugpy last year.
I am still having issues with timing out though :(
image

This is my config for the project, which I have tested and can confirm works in VSCode:

{
    "name": "Python: Remote Attach - 3DsMax",
    "type": "python",
    "request": "attach",
    "port": 3000,
    "pathMappings": [
        {
            "localRoot": "C:/p4/Tools/Art/Python",
            "remoteRoot": "C:/p4/Tools/Art/Python"
        }
    ]
}

The remote connect only works from VSCode if I am running 3DsMax 2021, which uses Python37.
When I try to connect to either 3DsMax or MotionBuild 2018 it times out the same, so my guess is there is a problem with the Python27 version.

Is there anything I can do to further investigate the cause?

@daveleroy
Copy link
Owner

daveleroy commented Jan 27, 2021

I'm pretty swamped but I'll try to take a look this weekend. I imagine there is some additional stuff they add to the configuration before they send it to the debug adapter or they are using some custom dap events to get this working.

Otherwise I would expect it to work

@munkybutt
Copy link
Author

So the problem seems to have a bit more to it.
I have logged an issue on the debugpy github as even VSCode will not connect to 3DsMax 2018, which has integrated Python27.
They might be related as they both time out:
microsoft/debugpy#532

@daniele-niero
Copy link

daniele-niero commented Feb 16, 2021

@munkybutt How to run the debugpy.listen from Max?

I do this from Maya: I find first the right path to the python interpreter that Maya uses then use the debugpy.configuration to tell debugpy to use that interpreter and then I start to listen.

With this, I can connect from Visual Studio Code, but not from Debugger in Sublime.

import sys, os
import debugpy

execu = os.path.join(os.path.dirname(sys.executable), 'mayapy.exe')
debugpy.configure(python=execu)
print debugpy.listen(address=('localhost', 5678))

@daveleroy I didn't look inside your code, so I'm only guessing here, but could it be you are not allowing debugpy.configure(python="path to interpreter") ?

@daveleroy
Copy link
Owner

Are you using the st3 version of Debugger? If so it probably doesn't support attach because as far as I remember debugpy attach is supposed to connect to the adapter through a socket which is only supported in st4. Note the special handling of attach here https://github.com/daveleroy/sublime_debugger/blob/master/modules/debugger/adapters/python.py that is not supported in the st3 version

If you are using st4 I do not know what the issue is but if they use any custom debug adapter extensions they are not supported.

If you grab a log from the Output: Debugger: Protocol panel I can look at it

@munkybutt
Copy link
Author

Hey @daniele-niero - yeah I am setting the correct interpreter via the python arg in the configure method, this is what allows it to work from VSCode.

The issue must be related to me using ST3 as @daveleroy suggests - I guess this will be unusable until ST4 is officially released.

Thanks for the info @daveleroy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants