【问题标题】:passing object in rpyc fails在 rpyc 中传递对象失败
【发布时间】:2012-08-15 05:27:27
【问题描述】:

我正在尝试使用 RPyC 将对象作为参数从客户端传递到服务器。但服务器无法访问该对象,我收到一个 AttributeError。

服务器代码:

class AgentService(rpyc.Service):
  def exposed_func(self, obj):
    return obj.name

客户端代码

self._conn = connect(agent_host, agent_port, config = {"allow_public_attrs" : True})
return self._conn.root.func(obj)

returns: AttributeError: cannot access 'name'.

我正在使用RPyC 服务并根据网站进行编码,这应该可以。

有什么想法吗?

【问题讨论】:

  • 大卫,感谢您的编辑 - 看起来更专业...

标签: python parameter-passing pass-by-reference rpyc


【解决方案1】:

config dict需要在客户端和服务器端进行调整。

如果只需要访问公共变量,则要更改的主要值是allow_public_attrs : True;如果需要访问私有和受保护的变量和方法(即以“_”开头的变量和方法),则更改为allow_all_attrs : True

在客户端,连接代码如上述问题中那样编写,而在服务器端代码如下:

server = ThreadedServer(MyService, port = 12345,
                        protocol_config = {"allow_public_attrs" : True})

有关所有可用配置选项的更多信息,请参阅:

http://rpyc.sourceforge.net/api/core_protocol.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    • 2019-08-01
    相关资源
    最近更新 更多