From daf59e2a7199181a689ac5c51bd360a03563f41b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 8 Oct 2009 08:10:37 +0200 Subject: mpd: catch errors when writing command. --- nephilim/mpd.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nephilim/mpd.py b/nephilim/mpd.py index bcdf3ac..560a225 100644 --- a/nephilim/mpd.py +++ b/nephilim/mpd.py @@ -157,15 +157,16 @@ class MPDClient(QtCore.QObject): return retval self._commandlist.append(retval) - def _writeline(self, line): - self._wfile.write("%s\n" % line) - self._wfile.flush() - def _writecommand(self, command, args=[]): parts = [command] for arg in args: parts.append('"%s"' % escape(str(arg))) - self._writeline(" ".join(parts)) + try: + self._wfile.write(' '.join(parts).encode('utf-8') + '\n') + self._wfile.flush() + except socket.error, e: + self.logger.error('Error sending command: %s.'%e) + self.disconnect_mpd() def _readline(self): line = self._rfile.readline() -- cgit v1.2.3