From 15c331e7966b824dd1883f707fee7408131bddb9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 20 Sep 2009 10:42:24 +0200 Subject: mpd/mpclient: catch socket errors when sending commands --- nephilim/mpclient.py | 5 ++--- nephilim/mpd.py | 8 +++++++- 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() -- cgit v1.2.3