Don't go crazy with plugin reload logic in the mpd backend in case of corrupted received messages

This commit is contained in:
Fabio Manganiello 2019-01-09 22:05:53 +01:00
parent 544979e7ff
commit 156e2e8b5a

View file

@ -50,24 +50,23 @@ class MusicMpdBackend(Backend):
plugin = None plugin = None
while not self.should_stop(): while not self.should_stop():
success = False
while not success:
try: try:
plugin = get_plugin('music.mpd') plugin = get_plugin('music.mpd')
if not plugin:
raise StopIteration
status = plugin.status().output status = plugin.status().output
if not status or status.get('state') is None:
raise StopIteration
track = plugin.currentsong().output track = plugin.currentsong().output
state = status['state'].lower() state = status['state'].lower()
playlist = status['playlist'] playlist = status['playlist']
success = True except StopIteration:
except Exception as e:
self.logger.exception(e)
self.logger.info('Reloading crashed MPD plugin')
try:
plugin = get_plugin('music.mpd', reload=True)
except:
pass pass
except Exception as e:
self.logger.debug(e)
finally:
time.sleep(self.poll_seconds) time.sleep(self.poll_seconds)
if state != last_state: if state != last_state: