我在应用程序中使用 rpyc 并遇到了一个小问题。
我只想知道是否可以更新远程属性?
我有一个测试服务器:
import rpyc
from rpyc.utils.server import ThreadedServer
class Test:
def __init__(self):
self._v = 0
@property
def V(self):
return self._v
@V.setter
def V(self, value):
self._v = value
class TestService(rpyc.Service):
def exposed_Test(self):
return Test()
if __name__ == '__main__':
t = ThreadedServer(TestService, port = 2942,
protocol_config={"allow_all_attrs":True})
t.start()
在 ipython 控制台中:
In [1]: import rpyc
In [2]: conn = rpyc.connect('localhost', 2942, config={'allow_all_attrs':True})
In [3]: test = conn.root.Test()
In [4]: test.V
Out[4]: 0
In [5]: test.V = 2
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-d3ae0dcd1075> in <module>()
----> 1 test.V = 2
<blah blah traceback>
AttributeError: cannot access 'V'
是否可以更新远程属性?