Skip to content

Commit

Permalink
Revert "Revert "Revert "Remove socket timeouts"" (#883)" (#965)
Browse files Browse the repository at this point in the history
This reverts commit 031d38c.
  • Loading branch information
bdraco authored Oct 7, 2024
1 parent 82ae884 commit c7799f1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pychromecast/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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",
Expand Down

0 comments on commit c7799f1

Please sign in to comment.