commandPort doesn't work in mayapy?

268 views
Skip to first unread message

Paul Molodowitch

unread,
Dec 4, 2014, 3:36:44 PM12/4/14
to python_inside_maya
Just wanted to confirm that I'm not doing something wrong, or that there isn't something in our startup process that's making this fail... but is it True that the commandPort command doesn't work if run from inside of mayapy?  (Note that it DOES work from "maya -prompt")...

Here's the code I was using to test:

To start:

port = XXX
import pymel.core  # just to startup maya
import maya.cmds as cmds
cmds.commandPort(n=":%s" % port, sourceType='python')
print "socket opened on port %s" % port

To connect:

import socket
port = XXX
mayaSock = socket.socket()
mayaSock.settimeout(.5)
mayaSock.connect(('localhost', port))
try:
    mayaSock.send(r'print "hello from the outside world!\n";')
    mayaSock.send(r'polyCube();')
finally:
    mayaSock.close()

Justin Israel

unread,
Dec 4, 2014, 4:01:59 PM12/4/14
to python_in...@googlegroups.com
It looks like the different between maya -prompt and the mayapy standalone environment is that the event loop isn't started. mayapy does open the port and accept clients, but the client requests hang because they aren't being services.

Check this out. Start a request from your client, and then in your mayapy "server" process do this:

import maya.utils as mu
mu.processIdleEvents()

Your client should get a reply :-)

Looks like you will have to do the old pumpThread approach!


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAssL7Z4Y5R6EsNmFra9LkV%2BmmubTYXEnXa6JGaSBXjv8%2Bv_Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Paul Molodowitch

unread,
Dec 4, 2014, 5:08:53 PM12/4/14
to python_inside_maya
Huh, interesting...hadn't even thought of that as a possible solution.  In this case, I can use maya -prompt - just means have to write some MEL... but the manual idle-thread-processing approach could help in some cases where I wanted to have an on-idle callback in mayapy. Thanks!

- Paul

Reply all
Reply to author
Forward
0 new messages