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 threading
import time
import logging
from artiq.protocols import pyon
from artiq.protocols.asyncio_server import AsyncioServer as _AsyncioServer
logger = logging.getLogger(__name__)
class RemoteError(Exception):
"""Raised when a RPC failed or raised an exception on the remote (server)
side.
@ -250,6 +254,9 @@ class BestEffortClient:
try:
self.__coninit(firstcon_timeout)
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()
else:
self.__conretry_thread = None
@ -281,6 +288,10 @@ class BestEffortClient:
time.sleep(self.__retry)
else:
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:
self.__socket.close()
# must be after __socket.close() to avoid race condition
@ -317,6 +328,10 @@ class BestEffortClient:
self.__send(obj)
obj = self.__recv()
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()
else:
if obj["status"] == "ok":