From 0cc4d9c8a0deebce5cafaa7cbd04078cd8cf60e3 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 16 Sep 2023 21:15:55 +0300 Subject: [PATCH] Handle TimeoutError in FC2WebSocket._main_loop --- fc2_live_dl/fc2.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fc2_live_dl/fc2.py b/fc2_live_dl/fc2.py index a4770d9..2a833a0 100644 --- a/fc2_live_dl/fc2.py +++ b/fc2_live_dl/fc2.py @@ -83,9 +83,15 @@ async def get_hls_information(self): async def _main_loop(self): while True: - msg = await asyncio.wait_for( - self._ws.receive_json(), self.heartbeat_interval - ) + try: + msg = await asyncio.wait_for( + self._ws.receive_json(), self.heartbeat_interval + ) + except asyncio.TimeoutError: + self._logger.debug(f'Got no messages for {self.heartbeat_interval} seconds, sending heartbeat') + await self._try_heartbeat() + continue + self._logger.trace("<", json.dumps(msg)[:100]) if self._output_file is not None: self._output_file.write("< ")