I am completely new to Pyro4. Been trying a lot of things to get my task done.
Remote machine
- Has a library in Python 2.7.
- Helps create an object for a hardware under test.
- Pyro4 based code to expose the library function used to create the object.
- All pre-requisites for Pyro4 taken care.
Local machine
- Code to nslookup by name and fetch the URI.
- Use the function to invoke the object creation on remote machine.
Observations:
Connection successful.
NSLookup successful
URI fetched and on remote machine I can see prints related to object creation.
On LOCAL MACHINE : I see below error.
File "C:\Python27\lib\site-packages\Pyro4\core.py", line 476, in _pyroInvoke raise data # if you see this in your traceback, you should probably inspect the remote traceback as well TypeError: don't know how to serialize class <type '_multiprocessing.PipeConnection'>. Give it vars() or an appropriate getstate
Remote machine code:
import Pyro4
import <some_library>
ip = REMOTE_MACHINE_IP daemon = Pyro4.Daemon(host=ip) ns = Pyro4.locateNS(host=ip)
@Pyro4.expose class RemoteMachine(object):
> def __init__(self):
self.adp = <some_library>.<some_function>
@Pyro4.expose
def create_obj(self, id, conn_fd):
_obj = self.adp(id)
# Set the file descriptor of the pipe to the object
_obj.pipe_fd = conn_fd
return _obj
uri = daemon.register(RemoteMachine) ns.register("_obj", uri)
print("URI : {}".format(uri)) print("NS : {}".format(ns)) print("Ready.") daemon.requestLoop()
Local machine code:
import Pyro4
ns = Pyro4.locateNS(REMOTE_MACHINE_IP, 9090)
uri = ns.lookup("_obj")
mr = Pyro4.Proxy(uri)
class RemoteMachine(object):
def create_obj(self, arg):
return mr.create_obj(arg)
obj = RemoteMR()
result = obj.create_obj(0)
print(result)
if __name__ == '__main__':
freeze_support()