From 156e2e8b5a495af2ca9505f0c46e043ad79b46ba Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 9 Jan 2019 22:05:53 +0100 Subject: [PATCH] Don't go crazy with plugin reload logic in the mpd backend in case of corrupted received messages --- platypush/backend/music/mpd/__init__.py | 33 ++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/platypush/backend/music/mpd/__init__.py b/platypush/backend/music/mpd/__init__.py index 57e6558e..1c21da71 100644 --- a/platypush/backend/music/mpd/__init__.py +++ b/platypush/backend/music/mpd/__init__.py @@ -50,25 +50,24 @@ class MusicMpdBackend(Backend): plugin = None while not self.should_stop(): - success = False + try: + plugin = get_plugin('music.mpd') + if not plugin: + raise StopIteration - 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: - self.logger.exception(e) - self.logger.info('Reloading crashed MPD plugin') - try: - plugin = get_plugin('music.mpd', reload=True) - except: - pass + status = plugin.status().output + if not status or status.get('state') is None: + raise StopIteration - time.sleep(self.poll_seconds) + track = plugin.currentsong().output + state = status['state'].lower() + playlist = status['playlist'] + except StopIteration: + pass + except Exception as e: + self.logger.debug(e) + finally: + time.sleep(self.poll_seconds) if state != last_state: if state == 'stop':