Skip to content

Commit c7799f1

Browse files
authored
Revert "Revert "Revert "Remove socket timeouts"" (#883)" (#965)
This reverts commit 031d38c.
1 parent 82ae884 commit c7799f1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pychromecast/socket_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767

6868
HB_PING_TIME = 10
6969
HB_PONG_TIME = 10
70+
POLL_TIME_BLOCKING = 5.0
71+
POLL_TIME_NON_BLOCKING = 0.01
7072
TIMEOUT_TIME = 30.0
7173
RETRY_TIME = 5.0
7274

@@ -538,7 +540,7 @@ def run(self) -> None:
538540
self.logger.debug("Thread started...")
539541
while not self.stop.is_set():
540542
try:
541-
if self._run_once() == 1:
543+
if self._run_once(timeout=POLL_TIME_BLOCKING) == 1:
542544
break
543545
except Exception: # pylint: disable=broad-except
544546
self._force_recon = True
@@ -553,7 +555,7 @@ def run(self) -> None:
553555
# Clean up
554556
self._cleanup()
555557

556-
def _run_once(self) -> int:
558+
def _run_once(self, timeout: float = POLL_TIME_NON_BLOCKING) -> int:
557559
"""Receive from the socket and handle data."""
558560
# pylint: disable=too-many-branches, too-many-statements, too-many-return-statements
559561

@@ -568,7 +570,7 @@ def _run_once(self) -> int:
568570

569571
# poll the socket, as well as the socketpair to allow us to be interrupted
570572
try:
571-
ready = self.selector.select()
573+
ready = self.selector.select(timeout)
572574
except (ValueError, OSError) as exc:
573575
self.logger.error(
574576
"[%s(%s):%s] Error in select call: %s",

0 commit comments

Comments
 (0)