From c7799f18af23f837f3f1bd2a6d4894f5f599edf5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 7 Oct 2024 01:39:09 -0500 Subject: [PATCH] Revert "Revert "Revert "Remove socket timeouts"" (#883)" (#965) This reverts commit 031d38c24c18aae3f92745955b7d68db4399a3af. --- pychromecast/socket_client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pychromecast/socket_client.py b/pychromecast/socket_client.py index 1d8eac10b..c308a51b9 100644 --- a/pychromecast/socket_client.py +++ b/pychromecast/socket_client.py @@ -67,6 +67,8 @@ HB_PING_TIME = 10 HB_PONG_TIME = 10 +POLL_TIME_BLOCKING = 5.0 +POLL_TIME_NON_BLOCKING = 0.01 TIMEOUT_TIME = 30.0 RETRY_TIME = 5.0 @@ -538,7 +540,7 @@ def run(self) -> None: self.logger.debug("Thread started...") while not self.stop.is_set(): try: - if self._run_once() == 1: + if self._run_once(timeout=POLL_TIME_BLOCKING) == 1: break except Exception: # pylint: disable=broad-except self._force_recon = True @@ -553,7 +555,7 @@ def run(self) -> None: # Clean up self._cleanup() - def _run_once(self) -> int: + def _run_once(self, timeout: float = POLL_TIME_NON_BLOCKING) -> int: """Receive from the socket and handle data.""" # pylint: disable=too-many-branches, too-many-statements, too-many-return-statements @@ -568,7 +570,7 @@ def _run_once(self) -> int: # poll the socket, as well as the socketpair to allow us to be interrupted try: - ready = self.selector.select() + ready = self.selector.select(timeout) except (ValueError, OSError) as exc: self.logger.error( "[%s(%s):%s] Error in select call: %s",