Skip to content

Commit

Permalink
Handle TimeoutError in FC2WebSocket._main_loop (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: user <user@localhost>
  • Loading branch information
15532th and user authored Sep 18, 2023
1 parent a6c973f commit ad4ee15
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions fc2_live_dl/fc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("< ")
Expand Down

0 comments on commit ad4ee15

Please sign in to comment.