rpyc modules execution interception

24 views
Skip to first unread message

nicholas pliatsikas

unread,
Jul 22, 2016, 5:09:16 AM7/22/16
to rpyc
Hi folks

Hoping someone can help with this, I'm looking to run a rpyc server in a separate thread within an application (specifically autodesk maya) 
and communicate with it from an external python interpreter running the client, utilizing the rpycs conn.modules proxy feature

The problem a lot of the apps commands that need to be run on the server thread are not thread safe

In order to get around this problem I would need to inject the command below somewhere into rpyc command execution pipe.
executeInMainThreadWithResult(x, *p, **kw)

In essence i want to replace the following SimpleXmlRpc I'm currently using with a more generic rpyc approach

import thread
from SimpleXMLRPCServer import *
from maya.utils import *


class mainThreadHandler(SimpleXMLRPCRequestHandler):
def _dispatch(self, method, params):
x = getattr(cmds,method)
kw = {}
p = []
for n in params:
if (isinstance(n, type({}))):
kw = n
else:
p.append(n)
p = tuple(p)
y = executeInMainThreadWithResult(x, *p, **kw)

return y
def log_message(self, format, *args):
print format % args

def dispatchForever(x):
server = SimpleXMLRPCServer(("127.0.0.1", 18999), mainThreadHandler, allow_none=1)
print "registering"
for n in dir(cmds):
xx= getattr(cmds, n)
if (callable(xx)):
server.register_function(getattr(cmds, n))
print "registering complete, serving"
server.serve_forever()
thread.start_new_thread(dispatchForever, (None,))

Any ideas?
Cheers
Nick
Reply all
Reply to author
Forward
0 new messages