Retry on MPD ConnectionError

This commit is contained in:
boyska 2016-07-18 12:15:28 +02:00
parent 0036750004
commit 52cf40b780
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9

View file

@ -3,7 +3,7 @@ import logging
import gevent import gevent
from gevent.queue import Queue from gevent.queue import Queue
from mpd import MPDClient from mpd import MPDClient, ConnectionError
from eventutils import ParentedLet, Timer from eventutils import ParentedLet, Timer
from audiogen import audiogenerate from audiogen import audiogenerate
@ -21,14 +21,23 @@ class MpcWatcher(ParentedLet):
ParentedLet.__init__(self, queue) ParentedLet.__init__(self, queue)
self.log = logging.getLogger(self.__class__.__name__) self.log = logging.getLogger(self.__class__.__name__)
self.conf = conf self.conf = conf
if client is None: self.client = client # assume it is already connected, or None
self.client = get_mpd_client(self.conf)
else: def refresh_client(self):
self.client = client # assume it is already connected self.client = get_mpd_client(self.conf)
def do_business(self): def do_business(self):
while True: while True:
status = self.client.idle()[0] try:
if self.client is None:
self.refresh_client()
self.log.info('idling')
status = self.client.idle()[0]
except ConnectionError:
# TODO: should we emit an error just in case?
self.client = None
continue
self.log.info(status) self.log.info(status)
yield ('mpc', status) yield ('mpc', status)