Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Revert "Remove socket timeouts"" (#883)" #965

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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