From 986aa525d7e5995ed7734b3314509418efba41fd Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Wed, 19 Apr 2023 03:29:45 +0200 Subject: [PATCH] Change wss_timeout type from int to float. --- bfxapi/client.py | 2 +- bfxapi/websocket/client/bfx_websocket_client.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bfxapi/client.py b/bfxapi/client.py index dd64d06..8fe3f12 100644 --- a/bfxapi/client.py +++ b/bfxapi/client.py @@ -13,7 +13,7 @@ class Client: *, rest_host: str = REST_HOST, wss_host: str = WSS_HOST, - wss_timeout: int = 60 * 15, + wss_timeout: float = 60 * 15, log_filename: Optional[str] = None, log_level: str = "INFO" ): diff --git a/bfxapi/websocket/client/bfx_websocket_client.py b/bfxapi/websocket/client/bfx_websocket_client.py index e78d0ea..ba2f70c 100644 --- a/bfxapi/websocket/client/bfx_websocket_client.py +++ b/bfxapi/websocket/client/bfx_websocket_client.py @@ -103,15 +103,15 @@ class BfxWebsocketClient: async def __connect(self): Reconnection = namedtuple("Reconnection", ["status", "attempts", "timestamp"]) reconnection = Reconnection(status=False, attempts=0, timestamp=None) - delay, timer, tasks = None, None, [] + delay = _Delay(backoff_factor=1.618) + + timer, tasks, on_timeout_event = None, [], asyncio.locks.Event() - on_timeout_event = asyncio.locks.Event() - - def _on_timeout(): + def _on_wss_timeout(): on_timeout_event.set() raise ReconnectionTimeoutError("Connection has been offline for too long " \ - f"without being able to reconnect (wss_timeout is set to {self.wss_timeout}s).") + f"without being able to reconnect (wss_timeout: {self.wss_timeout}s).") async def _connection(): nonlocal reconnection, timer, tasks @@ -191,8 +191,8 @@ class BfxWebsocketClient: task.cancel() reconnection = Reconnection(status=True, attempts=1, timestamp=datetime.now()) - timer = asyncio.get_event_loop().call_later(self.wss_timeout, _on_timeout) - delay = _Delay(backoff_factor=1.618) + + timer = asyncio.get_event_loop().call_later(self.wss_timeout, _on_wss_timeout) elif isinstance(error, socket.gaierror) and reconnection.status: self.logger.warning(f"Reconnection attempt no.{reconnection.attempts} has failed. " \ f"Next reconnection attempt in ~{round(delay.peek()):.1f} seconds. (at the moment " \