2727logger = logging .getLogger (__name__ )
2828
2929
30- class RPCConnectionError (ConnectionError ):
31- pass
32-
33-
3430class AutoTarget :
3531 """Use this as target value in clients for them to automatically connect
3632 to the target exposed by the server. Servers must have only one target."""
@@ -43,6 +39,13 @@ class IncompatibleServer(Exception):
4339 pass
4440
4541
42+ class RPCConnectionError (ConnectionError ):
43+ """Raised by the client when a method called fails due to connection
44+ problems with the RPC server.
45+ """
46+ pass
47+
48+
4649_init_string = b"ARTIQ pc_rpc\n "
4750
4851
@@ -78,18 +81,18 @@ class Client:
7881 automatically attempted. The user must call :meth:`~sipyco.pc_rpc.Client.close_rpc` to
7982 free resources properly after initialization completes successfully.
8083
81- If the remote server shuts down during operation, ConnectionAbortedError is
82- raised by Client methods. The user should call
83- :meth:`~sipyco.pc_rpc.Client.close_rpc` and then discard this object.
84+ If the remote server shuts down during operation, RPCConnectionError is
85+ raised by future calls to Client methods. The user should call
86+ :meth:`~sipyco.pc_rpc.Client.close_rpc` and then discard this object.
8487
8588 :param host: Identifier of the server. The string can represent a
8689 hostname or a IPv4 or IPv6 address (see
8790 ``socket.create_connection`` in the Python standard library).
8891 :param port: TCP port to use.
8992 :param target_name: Target name to select. ``IncompatibleServer`` is
9093 raised if the target does not exist.
91- Use :class:`.AutoTarget` for automatic selection if the server has only one
92- target.
94+ Use :class:`.AutoTarget` for automatic selection if the server has
95+ only one target.
9396 Use ``None`` to skip selecting a target. The list of targets can then
9497 be retrieved using :meth:`~sipyco.pc_rpc.Client.get_rpc_id`
9598 and then one can be selected later using :meth:`~sipyco.pc_rpc.Client.select_rpc_target`.
@@ -143,11 +146,15 @@ def get_local_host(self):
143146 return self .__socket .getsockname ()[0 ]
144147
145148 def get_valid_methods (self ):
146- """Returns a set of names of valid methods of the target"""
149+ """Returns a set of names of methods which can be called on
150+ the server"""
147151 return self .__valid_methods .copy ()
148152
149153 def is_closed (self ):
150- """Return True if the connection to the server has been closed"""
154+ """Return True if the connection to the server has been closed
155+
156+ This method will actively query the server for data to check
157+ if the connection is working. """
151158 self .__closed = not self .__socket_is_open ()
152159
153160 return self .__closed
@@ -231,9 +238,10 @@ class AsyncioClient:
231238 uses ``asyncio`` instead of blocking calls.
232239
233240 All RPC methods are coroutines. As with :class:`sipyco.pc_rpc.Client`,
234- methods will raise ConnectionAbortedError if the server closes the
235- connection. The user should call :meth:`~sipyco.pc_rpc.AsyncioClient.close_rpc`
236- and then discard this object.
241+ methods will raise RPCConnectionError if the server closes the
242+ connection. The user should call
243+ :meth:`~sipyco.pc_rpc.AsyncioClient.close_rpc` and then discard this
244+ object.
237245
238246 Concurrent access from different asyncio tasks is supported; all calls
239247 use a single lock.
@@ -248,8 +256,8 @@ def __init__(self):
248256
249257 async def connect_rpc (self , host , port , target_name ):
250258 """Connects to the server. This cannot be done in __init__ because
251- this method is a coroutine. See :class:`sipyco.pc_rpc.Client` for a description of the
252- parameters."""
259+ this method is a coroutine. See :class:`sipyco.pc_rpc.Client` for a
260+ description of the parameters."""
253261 self .__reader , self .__writer = \
254262 await asyncio .open_connection (host , port , limit = 100 * 1024 * 1024 )
255263 try :
@@ -329,7 +337,7 @@ def __send(self, obj):
329337 line = pyon .encode (obj ) + "\n "
330338 self .__writer .write (line .encode ())
331339
332- async def __recv (self ):
340+ async def __recv (self ):
333341 if not self .__closed :
334342 line = await self .__reader .readline ()
335343 if self .__closed or not line :
0 commit comments