我对 Pyro4 完全陌生。一直在尝试很多事情来完成我的基本任务。目标如下。任何帮助都会很有用。如果需要更多详细信息,请告诉我。
远程机器: 在 Python 2.7 中有一个库。 帮助为被测硬件创建对象。 基于 Pyro4 的代码公开用于创建对象的库函数。 Pyro4 的所有先决条件都得到了照顾。
本地机器: 按名称 nslookup 的代码并获取 URI。 使用函数调用远程机器上的对象创建。
观察:
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
远程机器代码:
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()
本地机器代码:
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()