Does anyone have experience with it? What are your thoughts, compared to other forms of RPC?
I found it hidden away amongst the default Python libraries and am quite astounded by it’s simplicity.
# From within Maya
from SimpleXMLRPCServer import SimpleXMLRPCServer
import threading
from maya import cmds
server = SimpleXMLRPCServer(("127.0.0.1", 8000))
server.register_function(cmds.createNode)
t = threading.Thread(target=server.serve_forever)
t.daemon = True
t.start()
And then, from a terminal.
>>> import xmlrpclib
>>> proxy = xmlrpclib.ServerProxy("http://127.0.0.1:8000/")
>>> proxy.createNode("mesh")
'polySurfaceShape1'
Resources:
I don't have much to say in either direction, since I have never used the builtin xml-rpc in my own server/client solution. But I think I used it once to connect to an instance of supervisor (the python-based process manager), which does expose an xml-rpc endpoint so that you can control it. Seems like xml-rpc is probably a lower performance solution that is good when you just need to send less frequent calls. Since it uses xml and makes httprequests, it has extra overhead in both the connection and the protocol.
Also, I think the builtin server in the python standard lib might be there for lower performance needs. The server isn't a serious production grade and most likely handles a single request at a time. I believe it also fully tears down the connection after each call, as opposed to solutions that could use keep-alive.
But it probably works just fine for the situation you outlined, where you are sending control commands to a local Maya. I doubt you would want to stand up a server and hit it with 10 clients.
--
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/CAFRtmOBOaQfQ0k2_dLavXb0zDOOR6%2Bt%2Bb%3DpjWz7mMdrBWKDvTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/CAFRtmOCOgXDFPLNuK_Pn%2BDsTEtY2FsDfnnYujYkMnTxeiE5cXA%40mail.gmail.com.
I wasn’t really having any problems with it, I was more wondering whether any of you had had any experience with it.
Considering it’s from 2001-2002, has a rather ugly import (with non-PEP08 names) spread across two top-level modules (for client and server) and contains the word “XML”, I can understand how a first impression might have gotten spoiled.
But it looks and works great.
It also supports batched calls; as in gathering up any number of RPC and sending them through a single request. I wish I came across this ages ago. :O
Some tests, with a single provider and consumer. Not fair, probably, it should probably use multiple consumers to show a difference here, but singles is all I’m looking for personally.
Synchronous 1600/sec
from SimpleXMLRPCServer import SimpleXMLRPCServer
import SocketServer
def null():
return True
server = SimpleXMLRPCServer(("0.0.0.0", 80), logRequests=False)
server.register_function(null)
server.serve_forever()
Threaded 1222/sec
from SimpleXMLRPCServer import SimpleXMLRPCServer
import SocketServer
def null():
return True
class ThreadedServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer):
pass
server = ThreadedServer(("0.0.0.0", 80), logRequests=False)
server.register_function(null)
server.serve_forever()
Forked 380/sec
from SimpleXMLRPCServer import SimpleXMLRPCServer
import SocketServer
def null():
return True
class ForkingServer(SocketServer.ForkingMixIn, SimpleXMLRPCServer):
pass
server = ForkingServer(("0.0.0.0", 80), logRequests=False)
server.register_function(null)
server.serve_forever()
Test
$ python -m timeit "import xmlrpclib;p = xmlrpclib.ServerProxy('http://192.168.131.153:8000');print p;[p.null() for x in xrange(100)]"
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2iRDvXk2rXJdx4Cm1LTP9qviiDFUWAjf_1FdTqX_WAEA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODjOVSDP32Jk%3D2%3Dp5JB7ZGeaWuPj7r2sgu5YYN6nwnrPQ%40mail.gmail.com.
I just discovered this, gives some perspective to the performance of the built-in Python version.
Using C, a client program starts (exec()), does 100 RPCs, and exits in 380 milliseconds. With just one RPC, it’s 26 ms. By calculation, this means the time for just an RPC is about 4 ms, about 280 RPCs per second.
A tad sceptical that Python outperforms C though. :S
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3MoTvAP4W1fig-eQFBWKB_ZNPHv0Oxpr9VtPYU068CrA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOALwOMc_Tf-DNp%3D_reZofEk%3D%2BcD0SBoN8Ek35oQVxAzoQ%40mail.gmail.com.
then I believe each http connection is fully torn down each time.
What does that mean? Is it of performance concern, or something else?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA29eHoTyJVZSgb8%2BmJKGNhUQ4sKZXvOLMqU2wVGk5OOcQ%40mail.gmail.com.
then I believe each http connection is fully torn down each time.
What does that mean? Is it of performance concern, or something else?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBShBrJMBdCiD_TPvkhHGvRyZd9VLJ8aAXyHq6mwKnwNQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA39fPS3B_qYKzfKAriWy%3DjPa6A%3DgvBj7sB0DPyKUXbL-A%40mail.gmail.com.
Without having tested this, and it being 3 years since I first wrote it, something like this might do the trick.
Replace this..
server.register_function(cmds.createNode)
With this..
for function in dir(cmds):
server.register_function(getattr(cmds, function))
Now you’ll have registered every single function in cmds and should be able to call them remotely.
Use at your own risk! :)