Форум сайта python.su
Скрипт сервера: server.py
import rpyc
class TEST001Service(rpyc.Service):
def exposed_getTest(self, obj):
print type(obj)
print dir(obj)
return obj.Execute(“MyTest”)
from rpyc.utils.server import ThreadedServer
s = ThreadedServer(TEST001Service)
s.start()
Скрипт клиента: client.py
import rpyc
class Request(object):
def __init__(self, request):
self.request = request
def Execute(self,msg):
result = {}
for i in request:
result = msg + “%d” % i
return result
c = rpyc.connect_by_service(“TEST001”)
r = Request()
print r.Execute(“TTT”)
print c.root.getTest(r)
1.Запускаем registry_server.py (из RPyC)
2.Стартую server.py
3. Стартую client.py
получаю на стороне сервера
<netref class ‘__main__.Request’>
['Execute', ‘__class__’, ‘__delattr__’, ‘__dict__’, ‘__doc__’, ‘__format__’, ‘__
getattribute__’, ‘__hash__’, ‘__init__’, ‘__module__’, ‘__new__’, ‘__reduce__’,
'__reduce_ex__', ‘__repr__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__subclass
hook__’, ‘__weakref__’, ‘request’]
получаю на стороне клиента
{1: ‘TTT1’, 2: ‘TTT2’, 3: ‘TTT3’, 4: ‘TTT4’, 8: ‘TTT8’, 9: ‘TTT9’} 1
C:\Python26\lib\site-packages\rpyc\core\vinegar.py:42: DeprecationWarning: BaseException.message has
been deprecated as of Python 2.6
attrval = getattr(val, name)
C:\Python26\lib\site-packages\rpyc\core\vinegar.py:98: DeprecationWarning: BaseException.message has
been deprecated as of Python 2.6
setattr(exc, name, attrval)
======= Remote traceback =======
Traceback (most recent call last):
File “C:\Python26\lib\site-packages\rpyc\core\protocol.py”, line 223, in _dispatch_request
res = self._HANDLERS(self, *args)
File “C:\Python26\lib\site-packages\rpyc\core\protocol.py”, line 432, in _handle_getattr
return self._access_attr(oid, name, (), “_rpyc_getattr”, “allow_getattr”, getattr)
File “C:\Python26\lib\site-packages\rpyc\core\protocol.py”, line 395, in _access_attr
raise AttributeError(“cannot access %r” % (name,))
AttributeError: cannot access ‘Execute’
——————————–
Traceback (most recent call last):
File “C:\Python26\lib\site-packages\rpyc\core\protocol.py”, line 223, in _dispatch_request
res = self._HANDLERS(self, *args)
File “C:\Python26\lib\site-packages\rpyc\core\protocol.py”, line 426, in _handle_call
return self._local_objects(*args, **dict(kwargs))
File “F:\ds40a\wrk\Proj_Scada\_prj\Proj_ScadaDataServer\test\rpyc_test\server.py”, line 7, in expo
sed_getTest
return obj.Execute(“MyTest”)
File “C:\Python26\lib\site-packages\rpyc\core\netref.py”, line 92, in __getattr__
return syncreq(self, consts.HANDLE_GETATTR, name)
File “C:\Python26\lib\site-packages\rpyc\core\netref.py”, line 45, in syncreq
return conn().sync_request(handler, oid, *args)
File “C:\Python26\lib\site-packages\rpyc\core\protocol.py”, line 342, in sync_request
raise obj
AttributeError: cannot access ‘Execute’
======= Local exception ========
Traceback (most recent call last):
File “F:\ds40a\wrk\Proj_Scada\_prj\Proj_ScadaDataServer\test\rpyc_test\client.py”, line 16, in <mo
dule>
print c.root.getTest(r)
File “C:\Python26\lib\site-packages\rpyc\core\netref.py”, line 123, in __call__
return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
File “C:\Python26\lib\site-packages\rpyc\core\netref.py”, line 45, in syncreq
return conn().sync_request(handler, oid, *args)
File “C:\Python26\lib\site-packages\rpyc\core\protocol.py”, line 342, in sync_request
raise obj
AttributeError: cannot access ‘Execute’
Вопрос - я где-то ошибся или RPyC не позволяет в качестве параметров для методов сервиса
использовать экземпляры классов?
Офлайн
в вашем случае для клиента тоже нужно писать def expose_Execute. В rpyc это настраивается
Офлайн
Спасибо, Андрей!
То, что нужно. Помогло!
Офлайн