Maya debug method

Nov 3, 2014 at 3:28 PM
Edited Nov 3, 2014 at 3:29 PM
Win7x64 + Maya2015SP5Ext1 + VS2012+PTVS2.1

ProjectSetting: http://c2n.me/jd5Dhd

I spent whole day trying make PTVS debugging works with Maya 2015 and still it didn't work.
As shown in this video http://www.youtube.com/watch?v=VTluEosS4Ts
i copied ptvsd from
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.1\ptvsd
to
C:\Users\<username>\Documents\Visual Studio 2012\Projects\SCRIPT\SCRIPT\ptvsd
and VS still didn't see ptvsd http://c2n.me/jd5A1w
So i tried to Add Environment (this thread https://pytools.codeplex.com/discussions/276754).
http://c2n.me/jd64Ew But it didn't work as well.
Can you please provide the way to make remote debugging works with Maya ?
I'm already tried pyCharm and Eclipse and debug work well and with no problems in this IDEs.
Coordinator
Nov 3, 2014 at 3:48 PM
Nov 3, 2014 at 8:15 PM
Edited Nov 3, 2014 at 8:15 PM
Yes.
And there is no information about solving ptsd error i've described earlier.
http://clip2net.com/s/jd5A1w
So if we find out how this error can be solved we can move farther.
Coordinator
Nov 3, 2014 at 8:20 PM
To clarify - is your own .py file located in "C:\Users\<username>\Documents\Visual Studio 2012\Projects\SCRIPT\SCRIPT"?

Also, note that the error that you're seeing is actually Intellisense warning indicating that VS couldn't locate the package. It won't preclude you from actually running your code, and it will run successfully if all the paths are right.
Nov 4, 2014 at 4:52 AM
Edited Nov 4, 2014 at 5:01 AM
Ok. So let's walk thru it step by step:
  1. http://c2n.me/jdfZ2N
  2. http://c2n.me/jdfZ4a
  3. http://c2n.me/jdfZ5W
  4. http://c2n.me/jdfZ6Y
  5. http://c2n.me/jdfZ9z
  6. http://c2n.me/jdfZa3
And there is no firewalls etc on my Notebook
Coordinator
Nov 4, 2014 at 4:59 PM
Hm, this is something new. It looks like the attempt to open the server socket was blocked.

Could it be that Maya itself blocks it for security reasons, by e.g. running those scripts in a sandbox? And it could be something specific to the new version of Maya.

First of all, I'd try experimenting with the endpoint. The default is 0.0.0.0:5678, which would make the socket accessible on all external interfaces. Try changing it to something more restrictive, and maybe a different port as well, just in case, e.g.:
ptvsd.enable_attach(secret=None, address=('127.0.0.1', 9999))
If that still doesn't work, then I would try it with a simplified repro - just create and bind your own socket directly:
import socket
server = socket.socket()
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(('127.0.0.1', 9999))
server.listen(1)
If you still get the same error with the above code snippet (which you should), you can then forward it to Maya support and ask them why it is not working, and if it's indeed some kind of sandbox, whether there's any configurable way to disable it.

(If you create a follow-up discussion on their forums, can you please cross-reference it here with a link so that other people who find this topic can see the other one as well?)
Nov 6, 2014 at 6:56 AM
Edited Nov 6, 2014 at 7:05 AM
Thank you Pavel. We have progress.
Now i can attach to remote process but i can't understand why it didn't stop on breakpoints.
Another words when i connect to maya the script is already done.
Here is the steps i made:
  1. https://www.dropbox.com/s/f68qsniw6ps01nv/01.png
  2. http://c2n.me/je7jix
  3. http://c2n.me/je7jjA
  4. http://c2n.me/je7jky
By the way testyTest.py script is external file. I just open it in VS2012. It is not in Project.
Can this somehow cause VS to skip breakpoints ?
Coordinator
Nov 6, 2014 at 7:21 AM
enable_attach starts the debugging server on the background thread, but continues execution from there. If Maya unloads the interpreter instance after running the script, the debugging server will also go away.

Try adding ptvsd.wait_for_attach() right after enable_attach - this will block script execution until you actually attach.
Coordinator
Nov 6, 2014 at 7:22 AM
By the way, since it sounds like you figured out why it couldn't bind to the socket, can you share the solution to that problem here, so that other people running into it can find it?
Nov 6, 2014 at 10:32 AM
Unfortunately, Pavel, i didn't figured out why exactly Maya didn't bind socket last time.
When i start this thread, i reboot my Notebook a couple times and still it have socket error.
Tomorrow i just tried the same script and it just works. And with ptsd.wait_for attach(), breakpoints works as well.
Thank you so much for the speedy reply and help.
Coordinator
Nov 6, 2014 at 3:15 PM
Great to hear that it's working for you!
Nov 8, 2014 at 7:33 AM
By the way Pavel, can we solve intellisense error that i have ?
And is there any other way to make PTVS highlight same identifiers when they
selected (https://pytools.codeplex.com/workitem/129) ?
Coordinator
Nov 8, 2014 at 7:46 AM
Is it just ptvsd, or is it a general problem with one module importing another module in your project?

One thing you might want to do is make sure that your project's home path (in project property) is set properly to reference the folder where your script and ptvsd both are.

As for #129, the only way to make PTVS do it is to implement the feature. We don't have a definitive plan yet, but given how many votes it has, it is likely to end up on the todo list for the next release.
Nov 8, 2014 at 12:38 PM
Edited Nov 8, 2014 at 12:41 PM
Well, problem is:
http://c2n.me/jf30Cx
CTRL+SPACE didn't show completions for imported module maya.cmds which is a Autodesk Maya main module.
But for ptvsd and default VS or System modules like "math" etc it works.
Maybe the problem is in the PROJECT settings or environment ?
http://c2n.me/jf30GA
There were previously created completionDB but completion for maya.cmds didn't work either.
So i delete environment variable.
http://c2n.me/jf30Eo
Coordinator
Nov 8, 2014 at 11:38 PM
If I remember correctly, Maya puts its entire Lib folder in a zip file, and we don't know how to handle that (yet) - see:

https://pytools.codeplex.com/workitem/1011

If that's the case for 2015, as well, I would suggest unpacking that entire .zip, including Maya modules, and then adding it as a custom environment.

One other thing of note is that some of those modules are probably native modules written in C. Since type inference engine can't work on them like it does on pure Python code, it tries to parse docstrings for type information instead - so the quality of completions for such modules depends on the quality of their docstrings. As there's no uniform standard for documenting types that way, we try to be flexible to adapt to a wide range of approaches (covering e.g. PyQt and numpy), but occasionally we run into a binary module which uses some scheme that's different enough that our heuristics don't work. If this is what you're running into, file a bug on those specific modules that don't get completions, and it would also help if you can provide some of their docstrings.