forked from M-Labs/artiq
1
0
Fork 0

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
1 changed files with 10 additions and 5 deletions

View File

@ -57,8 +57,7 @@ def _validate_target_name(target_name, target_names):
target_name = target_names[0] target_name = target_names[0]
elif target_name not in target_names: elif target_name not in target_names:
raise IncompatibleServer( raise IncompatibleServer(
"valid target name(s): " + "valid target name(s): " + " ".join(sorted(target_names)))
" ".join(sorted(target_names)))
return target_name return target_name
@ -92,9 +91,14 @@ class Client:
Use ``None`` to skip selecting a target. The list of targets can then 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 be retrieved using ``get_rpc_id`` and then one can be selected later
using ``select_rpc_target``. 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): def __init__(self, host, port, target_name=AutoTarget, timeout=None):
self.__socket = socket.create_connection((host, port)) self.__socket = socket.create_connection((host, port), timeout)
try: try:
self.__socket.sendall(_init_string) self.__socket.sendall(_init_string)
@ -485,7 +489,8 @@ class Server(_AsyncioServer):
obj = {"status": "ok", "ret": doc} obj = {"status": "ok", "ret": doc}
elif obj["action"] == "call": elif obj["action"] == "call":
logger.debug("calling %s", _PrettyPrintCall(obj)) 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() self._terminate_request.set()
obj = {"status": "ok", "ret": None} obj = {"status": "ok", "ret": None}
else: else: