From 0cccdd01b50b2d5353e4a8d0b5d58b919ca3c531 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 5 Apr 2018 23:15:24 -0400 Subject: [PATCH] Only log when the network first goes down --- piker/brokers/core.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/piker/brokers/core.py b/piker/brokers/core.py index ae58c837..fac9d72c 100644 --- a/piker/brokers/core.py +++ b/piker/brokers/core.py @@ -49,15 +49,21 @@ async def quote(brokermod: ModuleType, tickers: [str]) -> dict: async def wait_for_network(get_quotes, sleep=1): """Wait until the network comes back up. """ + down = False while True: try: with trio.move_on_after(1) as cancel_scope: - return await get_quotes() + quotes = await get_quotes() + if down: + log.warn("Network is back up") + return quotes if cancel_scope.cancelled_caught: log.warn("Quote query timed out") continue except socket.gaierror: - log.warn(f"Network is down waiting for reestablishment...") + if not down: # only report/log network down once + log.warn(f"Network is down waiting for re-establishment...") + down = True await trio.sleep(sleep)