2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-29 05:03:34 +08:00

pc_rpc.Client: support socket timeouts

... and fix two flake8 errors.
This commit is contained in:
Robert Jördens 2016-02-02 15:14:24 -07:00
parent 55006119c8
commit c105949155

View File

@ -57,8 +57,7 @@ def _validate_target_name(target_name, target_names):
target_name = target_names[0]
elif target_name not in target_names:
raise IncompatibleServer(
"valid target name(s): " +
" ".join(sorted(target_names)))
"valid target name(s): " + " ".join(sorted(target_names)))
return target_name
@ -92,9 +91,14 @@ class Client:
Use ``None`` to skip selecting a target. The list of targets can then
be retrieved using ``get_rpc_id`` and then one can be selected later
using ``select_rpc_target``.
:param timeout: Socket operation timeout. Use ``None`` for blocking
(default), ``0`` for non-blocking, and a finite value to raise
``socket.timeout`` if an operation does not complete within the
given time. See also ``socket.create_connection()`` and
``socket.settimeout()`` in the Python standard library.
"""
def __init__(self, host, port, target_name=AutoTarget):
self.__socket = socket.create_connection((host, port))
def __init__(self, host, port, target_name=AutoTarget, timeout=None):
self.__socket = socket.create_connection((host, port), timeout)
try:
self.__socket.sendall(_init_string)
@ -485,7 +489,8 @@ class Server(_AsyncioServer):
obj = {"status": "ok", "ret": doc}
elif obj["action"] == "call":
logger.debug("calling %s", _PrettyPrintCall(obj))
if self.builtin_terminate and obj["name"] == "terminate":
if (self.builtin_terminate and obj["name"] ==
"terminate"):
self._terminate_request.set()
obj = {"status": "ok", "ret": None}
else: