From 4f1b17d6b72946b60f79b8c3f5fa5557710b9aac Mon Sep 17 00:00:00 2001 From: kaliko Date: Tue, 17 Jun 2014 16:59:52 +0200 Subject: [PATCH] Fixed SIGHUP issue hopefully. Need python-musicpd >= 0.4.1 --- setup.py | 2 +- sima/client.py | 12 ++++++++++-- sima/core.py | 6 +++++- sima/lib/player.py | 4 ++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 46f06a2..036f85e 100755 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ setup(name='MPD_sima', keywords='MPD', long_description=DESCRIPTION, classifiers=classifiers, - install_requires=['python-musicpd', 'requests'], + install_requires=['python-musicpd>=0.4.1', 'requests>= 2.0.2'], packages=find_packages(exclude=["tests"]), include_package_data=True, data_files=data_files, diff --git a/sima/client.py b/sima/client.py index c04b259..8481f5c 100644 --- a/sima/client.py +++ b/sima/client.py @@ -288,9 +288,9 @@ class PlayerClient(Player): def monitor(self): curr = self.current try: - self._client.send_idle('database', 'playlist', 'player', 'options') + self.send_idle('database', 'playlist', 'player', 'options') select([self._client], [], [], 60) - ret = self._client.fetch_idle() + ret = self.fetch_idle() if self.__skipped_track(curr): ret.append('skipped') if 'database' in ret: @@ -299,6 +299,14 @@ class PlayerClient(Player): except (MPDError, IOError) as err: raise PlayerError("Couldn't init idle: %s" % err) + def clean(self): + """Clean blocking event (idle) and pending commands + """ + if 'idle' in self._client._pending: + self._client.noidle() + elif self._client._pending: + self.log.warning('pending commands: {}'.format(self._client._pending)) + def remove(self, position=0): self._client.delete(position) diff --git a/sima/core.py b/sima/core.py index cf011c7..7a17c5f 100644 --- a/sima/core.py +++ b/sima/core.py @@ -123,14 +123,18 @@ class Sima(Daemon): def hup_handler(self, signum, frame): self.log.warning('Caught a sighup!') - self.player.disconnect() + # Cleaning pending command + self.player.clean() self.foreach_plugin('shutdown') + self.player.disconnect() raise SigHup('SIGHUP caught!') def shutdown(self): """General shutdown method """ self.log.warning('Starting shutdown.') + # Cleaning pending command + self.player.clean() self.foreach_plugin('shutdown') self.player.disconnect() diff --git a/sima/lib/player.py b/sima/lib/player.py index 6b6d2cb..37b3c72 100644 --- a/sima/lib/player.py +++ b/sima/lib/player.py @@ -57,6 +57,10 @@ class Player(object): """ raise NotImplementedError + def clean(self): + """Any cleanup necessary""" + pass + def remove(self, position=0): """Removes the oldest element of the playlist (index 0) """ -- 2.39.5