From ad4ee155de6bb56f40d37f58ce8b68177b8d119b Mon Sep 17 00:00:00 2001 From: 15532th <92187332+15532th@users.noreply.github.com> Date: Mon, 18 Sep 2023 10:59:58 +0300 Subject: [PATCH] Handle TimeoutError in FC2WebSocket._main_loop (#48) Co-authored-by: user --- 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("< ")