From b0dced9c9fd434cc9b6beba215ac67bc1a7c2116 Mon Sep 17 00:00:00 2001 From: Ganden Schaffner Date: Thu, 16 Dec 2021 00:00:00 -0800 Subject: [PATCH] Fix outdated documentation on _conn, on_connect, and on_disconnect Corresponds to changes introduced in RPyC 4.0. --- docs/docs/services.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/docs/services.rst b/docs/docs/services.rst index f9204fc4..7e2e97dd 100644 --- a/docs/docs/services.rst +++ b/docs/docs/services.rst @@ -67,15 +67,11 @@ If you wish to change the name of your service, or specify a list of aliases, se The first name in this list is considered the "proper name" of the service, while the rest are considered aliases. This distinction is meaningless to the protocol and the registry server. -Your service class may also define two special methods: ``on_connect(self)`` and -``on_disconnect(self)``. These methods are invoked, not surprisingly, when a connection +Your service class may also define two special methods: ``on_connect(self, conn)`` and +``on_disconnect(self, conn)``. These methods are invoked, not surprisingly, when a connection has been established, and when it's been disconnected. Note that during ``on_disconnect``, the connection is already dead, so you can no longer access any remote objects. -Other than that, your service instance has the ``_conn`` attribute, which represents the -:class:`~rpyc.core.protocol.Connection` that it serves. This attribute already -exists when ``on_connected`` is called. - .. note:: Try to avoid overriding the ``__init__`` method of the service. Place all initialization-related code in ``on_connect``. @@ -109,8 +105,11 @@ it's not the most common use case, two-sides services are quite useful. Consider And this server:: class ServerService(rpyc.Service): + def on_connect(self, conn): + self.conn = conn + def exposed_bar(self): - return self._conn.root.foo() + "bar" + return self.conn.root.foo() + "bar" The client can invoke ``conn.root.bar()`` on the server, which will, in turn, invoke ``foo`` back on the client. The final result would be ``"foobar"``.