[Python-modules-commits] [pychromecast] 08/15: Force reconnection if there is an IO error.
Ruben Undheim
rubund-guest at moszumanska.debian.org
Sat Sep 12 12:30:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
rubund-guest pushed a commit to branch master
in repository pychromecast.
commit 724a0457b96b43a23bddc4cb7221b6fc0d44ee10
Author: Ryan Kraus <rmkraus at gmail.com>
Date: Thu Aug 27 01:09:18 2015 -0400
Force reconnection if there is an IO error.
---
pychromecast/socket_client.py | 33 +++++++++++++++++++++++++--------
setup.py | 2 +-
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/pychromecast/socket_client.py b/pychromecast/socket_client.py
index ba52e67..10800a9 100644
--- a/pychromecast/socket_client.py
+++ b/pychromecast/socket_client.py
@@ -97,6 +97,8 @@ class SocketClient(threading.Thread):
self.logger = logging.getLogger(__name__)
+ self._force_recon = False
+
self.tries = tries
self.host = host
@@ -160,6 +162,7 @@ class SocketClient(threading.Thread):
self.receiver_controller.update_status()
self.heartbeat_controller.ping()
self.heartbeat_controller.reset()
+ self._force_recon = False
self.logger.debug("Connected!")
break
@@ -214,10 +217,11 @@ class SocketClient(threading.Thread):
""" Start polling the socket. """
# pylint: disable=too-many-branches
self.heartbeat_controller.reset()
+ self._force_recon = False
while not self.stop.is_set():
# check if connection is expired
- if self.heartbeat_controller.is_expired():
+ if self.heartbeat_controller.is_expired() or self._force_recon:
self.logger.error(
"Error communicating with socket, resetting connection")
try:
@@ -226,12 +230,20 @@ class SocketClient(threading.Thread):
self.stop.set()
continue
- # read messages from chromecast
+ # poll the socket
can_read, _, _ = select.select([self.socket], [], [], POLL_TIME)
- if self.socket in can_read:
- message = self._read_message()
- data = _json_from_message(message)
- else:
+
+ # read messages from chromecast
+ message = data = None
+ if self.socket in can_read and not self._force_recon:
+ try:
+ message = self._read_message()
+ except socket.error:
+ self._force_recon = True
+ self.logging.error('Error reading from socket.')
+ else:
+ data = _json_from_message(message)
+ if not message:
continue
# route message to handlers
@@ -260,7 +272,7 @@ class SocketClient(threading.Thread):
_message_to_string(message, data))
else:
- self.logger.warning(
+ self.logger.debug(
"Received unknown namespace: %s",
_message_to_string(message, data))
@@ -352,7 +364,12 @@ class SocketClient(threading.Thread):
if not force and self.stop.is_set():
raise PyChromecastStopped("Socket client's thread is stopped.")
if not self.connecting:
- self.socket.sendall(be_size + msg.SerializeToString())
+ try:
+ self.socket.sendall(be_size + msg.SerializeToString())
+ except socket.error as err:
+ self._force_recon = True
+ self.logger.error('Error writing to socket.')
+ raise err
else:
raise NotConnected("Chromecast is connecting...")
diff --git a/setup.py b/setup.py
index cabb940..0b2de14 100644
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup(
name='PyChromecast',
- version='0.6.10',
+ version='0.6.11',
license='MIT',
url='https://github.com/balloob/pychromecast',
author='Paulus Schoutsen',
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pychromecast.git
More information about the Python-modules-commits
mailing list