From fcdc4d1af86da9d7b8cd0b979e0a74a1057ffc61 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 17 Apr 2018 16:43:39 +0200 Subject: [PATCH] Reload the MPD plugin in case of any errors during the status retrieval --- platypush/backend/music/mpd/__init__.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/platypush/backend/music/mpd/__init__.py b/platypush/backend/music/mpd/__init__.py index 1bda316a9e..c786e49093 100644 --- a/platypush/backend/music/mpd/__init__.py +++ b/platypush/backend/music/mpd/__init__.py @@ -30,18 +30,22 @@ class MusicMpdBackend(Backend): plugin = None while not self.should_stop(): - while not plugin: - plugin = get_plugin('music.mpd') - if not plugin: + success = False + + while not success: + try: + plugin = get_plugin('music.mpd') + status = plugin.status().output + track = plugin.currentsong().output + state = status['state'].lower() + playlist = status['playlist'] + success = True + except Exception as e: + logging.exception(e) logging.info('Reloading crashed MPD plugin') plugin = get_plugin('music.mpd', reload=True) time.sleep(self.poll_seconds) - status = plugin.status().output - track = plugin.currentsong().output - state = status['state'].lower() - playlist = status['playlist'] - if state != last_state: if state == 'stop': self.bus.post(MusicStopEvent(status=status, track=track))