From 9c4f5e437247f90c53d771611a0329d8543734f2 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 7 Sep 2017 07:50:51 +0000 Subject: [PATCH] Catch even more exceptions to stay connected or reconnect --- yaboli/connection.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/yaboli/connection.py b/yaboli/connection.py index 4a61f1b..5cfa4c3 100644 --- a/yaboli/connection.py +++ b/yaboli/connection.py @@ -73,7 +73,11 @@ class Connection: self._clean_up_futures() self._clean_up_tasks() - await self._ws.close() # just to make sure + try: + await self._ws.close() # just to make sure + except: + pass # errors are not useful here + await self._pingtask # should stop now that the ws is closed self._ws = None @@ -92,7 +96,7 @@ class Connection: logger.warning("Ping timed out.") await self._ws.close2() break - except websockets.ConnectionClosed: + except (websockets.ConnectionClosed, ConnectionResetError): break else: await asyncio.sleep(self.ping_delay) @@ -103,7 +107,10 @@ class Connection: """ if self._ws: - await self._ws.close() + try: + await self._ws.close() + except: + pass # errors not useful here if self._runtask: await self._runtask