特定のモジュールをインポートする RpyC サーバーがあります。このモジュール内のクラスを公開して、このクラスをクライアント側から継承できるようにする必要があります。
テスト目的で、モジュールのインポート/公開を削除し、RPyC サービス内に exposed_TestClass という単純なクラスを作成しました。
サーバー側: rpyc_server.py
import rpyc
from rpyc.utils.server import ThreadedServer
class MyService(rpyc.Service):
class exposed_TestClass:
def exposed_Exec(self):
print("original print of class")
t = ThreadedServer(MyService, port=12345)
t.start()
クライアント側: python3 シェル
>>> import rpyc
>>> conn = rpyc.connect("localhost", 12345)
>>> conn.root.TestClass
<class 'exposed_TestClass'>
>>> conn.root.TestClass()
<exposed_TestClass object at 0x7f2dda642588>
>>> #calling the Exec function also works, prints at server side
>>> conn.root.TestClass().Exec()
>>>
>>>
>>> # test inheriting class
>>> class MyClass(conn.root.TestClass):
... def NewMethod(self):
... print("printing from new method")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/rpyc/core/netref.py", line 220, in method
return syncreq(_self, consts.HANDLE_CALLATTR, name, args, kwargs)
File "/usr/lib/python3/dist-packages/rpyc/core/netref.py", line 74, in syncreq
conn = object.__getattribute__(proxy, "____conn__")
AttributeError: 'str' object has no attribute '____conn__'