async def _inner_messages( self, ws: websockets.WebSocketClientProtocol) -> AsyncIterable[str]: try: while True: msg: str = await asyncio.wait_for(ws.recv(), timeout=self.MESSAGE_TIMEOUT) yield msg except asyncio.TimeoutError: await asyncio.wait_for(ws.ping(), timeout=self.PING_TIMEOUT) except websockets.exceptions.ConnectionClosed: return finally: await ws.close()
async def _inner_messages( self, ws: websockets.WebSocketClientProtocol) -> AsyncIterable[str]: try: while True: try: msg: str = await asyncio.wait_for( ws.recv(), timeout=self.MESSAGE_TIMEOUT) msg = bitmart_utils.decompress_ws_message(msg) self._last_recv_time = time.time() yield msg except asyncio.TimeoutError: await asyncio.wait_for(ws.ping(), timeout=self.PING_TIMEOUT) self._last_recv_time = time.time() except asyncio.TimeoutError: self.logger().warning( "WebSocket ping timed out. Going to reconnect...") return except websockets.exceptions.ConnectionClosed: return finally: await ws.close()