summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-09-20 10:42:24 +0200
committerAnton Khirnov <wyskas@gmail.com>2009-09-20 10:42:24 +0200
commit15c331e7966b824dd1883f707fee7408131bddb9 (patch)
treef5f5e1df766ce567dbe5704b77609999014eeea9
parent48b6568f190dd92fa717af02c37bd806cdbc2624 (diff)
mpd/mpclient: catch socket errors when sending commands
-rw-r--r--nephilim/mpclient.py5
-rw-r--r--nephilim/mpd.py8
2 files changed, 9 insertions, 4 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index 9e287d7..4e9ce34 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -84,9 +84,8 @@ class MPClient(QtCore.QObject):
def disconnect_mpd(self):
"""Disconnect from MPD."""
self.logger.info('Disconnecting from MPD...')
- if not self._client:
- self.logger.warning('Attempted to disconnect when not connected.')
- self._client.disconnect_mpd()
+ if self._client:
+ self._client.disconnect_mpd()
def password(self, password):
"""Use the password to authenticate with MPD."""
diff --git a/nephilim/mpd.py b/nephilim/mpd.py
index 97aa54f..bcdf3ac 100644
--- a/nephilim/mpd.py
+++ b/nephilim/mpd.py
@@ -144,7 +144,13 @@ class MPDClient(QtCore.QObject):
def _docommand(self, command, args, retval):
if self._commandlist is not None and not callable(retval):
raise CommandListError("%s not allowed in command list" % command)
- self._writecommand(command, args)
+ try:
+ self._writecommand(command, args)
+ except socket.error, e:
+ self.logger.error('Error sending command: %s.'%e)
+ self.disconnect_mpd()
+ return None
+
if self._commandlist is None:
if callable(retval):
return retval()