forked from M-Labs/artiq
1
0
Fork 0

pc_rpc/BestEffortClient: add logging

This commit is contained in:
Sebastien Bourdeauducq 2015-02-12 00:21:39 +08:00
parent a7405dea1c
commit 6d11da3887
1 changed files with 15 additions and 0 deletions

View File

@ -17,11 +17,15 @@ import asyncio
import traceback import traceback
import threading import threading
import time import time
import logging
from artiq.protocols import pyon from artiq.protocols import pyon
from artiq.protocols.asyncio_server import AsyncioServer as _AsyncioServer from artiq.protocols.asyncio_server import AsyncioServer as _AsyncioServer
logger = logging.getLogger(__name__)
class RemoteError(Exception): class RemoteError(Exception):
"""Raised when a RPC failed or raised an exception on the remote (server) """Raised when a RPC failed or raised an exception on the remote (server)
side. side.
@ -250,6 +254,9 @@ class BestEffortClient:
try: try:
self.__coninit(firstcon_timeout) self.__coninit(firstcon_timeout)
except: except:
logger.warning("first connection attempt to %s:%d[%s] failed, "
"retrying in the background",
self.__host, self.__port, self.__target_name)
self.__start_conretry() self.__start_conretry()
else: else:
self.__conretry_thread = None self.__conretry_thread = None
@ -281,6 +288,10 @@ class BestEffortClient:
time.sleep(self.__retry) time.sleep(self.__retry)
else: else:
break break
if not self.__conretry_terminate:
logger.warning("connection to %s:%d[%s] established in "
"the background",
self.__host, self.__port, self.__target_name)
if self.__conretry_terminate and self.__socket is not None: if self.__conretry_terminate and self.__socket is not None:
self.__socket.close() self.__socket.close()
# must be after __socket.close() to avoid race condition # must be after __socket.close() to avoid race condition
@ -317,6 +328,10 @@ class BestEffortClient:
self.__send(obj) self.__send(obj)
obj = self.__recv() obj = self.__recv()
except: except:
logger.warning("connection failed while attempting "
"RPC to %s:%d[%s], re-establishing connection "
"in the background",
self.__host, self.__port, self.__target_name)
self.__start_conretry() self.__start_conretry()
else: else:
if obj["status"] == "ok": if obj["status"] == "ok":