Skip to content

Commit

Permalink
Allow receive timeout to be None for infinite hang
Browse files Browse the repository at this point in the history
  • Loading branch information
Latent-Logic committed Oct 17, 2023
1 parent eb54a7b commit c46c0be
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions twitchAPI/chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def __init__(self,
is_verified_bot: bool = False,
initial_channel: Optional[List[str]] = None,
callback_loop: Optional[asyncio.AbstractEventLoop] = None,
no_message_reset_time: int = 10):
no_message_reset_time: Optional[float] = 10):
"""
:param twitch: A Authenticated twitch instance
:param connection_url: alternative connection url |default|:code:`None`
Expand All @@ -572,7 +572,7 @@ def __init__(self,
self.ping_jitter: int = 4
"""Jitter in seconds for ping messages. This should usually not be changed."""
self._callback_loop = callback_loop
self.no_message_reset_time: int = no_message_reset_time
self.no_message_reset_time: Optional[float] = no_message_reset_time
self.listen_confirm_timeout: int = 30
"""Time in second that any :code:`listen_` should wait for its subscription to be completed."""
self.reconnect_delay_steps: List[int] = [0, 1, 2, 4, 8, 16, 32, 64, 128]
Expand Down Expand Up @@ -881,6 +881,7 @@ async def _send_message(self, message: str):
await self.__connection.send_str(message)

async def __task_receive(self):
receive_timeout = None if self.no_message_reset_time is None else self.no_message_reset_time * 60
try:
handlers: Dict[str, Callable] = {
'PING': self._handle_ping,
Expand All @@ -900,7 +901,7 @@ async def __task_receive(self):
}
while not self.__connection.closed:
try: # At minimum we should receive a PING request just under every 5 minutes
message = await self.__connection.receive(timeout=self.no_message_reset_time*60)
message = await self.__connection.receive(timeout=receive_timeout)
except asyncio.TimeoutError:
self.logger.warning(f"Reached timeout for websocket receive, will attempt a reconnect")
if self.__running:
Expand Down

0 comments on commit c46c0be

Please sign in to comment.