cannot get the example to work

40 views
Skip to first unread message

dan.b...@huawei.com

unread,
Nov 13, 2018, 8:31:34 AM11/13/18
to rpyc
I'm trying to get the example from "decoupled services" to work. Is there a mistake in the example, or am I doing something wrong?

Here's my client
Enter code import rpyc

class ClientOpsService(rpyc.Service):
    def on_connect(self, conn):
        # code that runs when a connection is created
        # (to init the service, if needed)
        pass

    def on_disconnect(self, conn):
        # code that runs after the connection has already closed
        # (to finalize the service, if needed)
        pass

    def exposed_ops_ping(self): # this is an exposed method
        return "ops-pong"

c = rpyc.connect("localhost", 18861, service = ClientOpsService)

ret=c.root.get_answer()
print(f"ret={ret}")here...

and here's my server
Enter code herimport rpyc
import sys

class ServerService(rpyc.Service):

    def exposed_get_answer(self): # this is an exposed method
        print(f"{sys._getframe(  ).f_code.co_name} called")
        r = self._conn.root.ops_ping()
        print(r)
        return 42

if __name__ == "__main__":
    client_service=None
    client_func=None
    from rpyc.utils.server import ThreadedServer

    t = ThreadedServer(ServerService(), port=18861)
    t.start()e...


and the result:
Enter code heredan@dan-om-linux:~/work/om_v1.0/src/control/sample_rpyc$ python my_client.py  
Traceback (most recent call last):
 File "my_client.py", line 25, in <module>
   ret=c.root.get_answer()
 File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/netref.py", line 199, in __call__
   return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
 File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/netref.py", line 75, in syncreq
   return conn.sync_request(handler, proxy, *args)
 File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/protocol.py", line 471, in sync_request
   return self.async_request(handler, *args, timeout=timeout).value
 File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/async_.py", line 97, in value
   raise self._obj
AttributeError: 'ServerService' object has no attribute '_conn'

========= Remote Traceback (1) =========
Traceback (most recent call last):
 File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/protocol.py", line 329, in _dispatch_request
   res = self._HANDLERS[handler](self, *args)
 File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/protocol.py", line 590, in _handle_call
   return obj(*args, **dict(kwargs))
 File "my_service.py", line 9, in exposed_get_answer
   r = self._conn.root.ops_ping()
AttributeError: 'ServerService' object has no attribute '_conn'


...

The documentation page https://rpyc.readthedocs.io/en/latest/docs/services.html#services
say that the server can call self._conn.root.foo() which is exposed by the client service, yes soemthing is wrong obviously

Reply all
Reply to author
Forward
0 new messages