From a3446621f465ee3e0b8ef630c9239536ae9b264a Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Mon, 24 Dec 2012 13:55:46 +0100 Subject: [PATCH] Fix use of threading.Event for Python 2.6 and clear connected state. threading.Event's wait method returns None on python pre 2.7, which means all searches would fail. This also corrects that fact that we weren't clearing the connected threading event on disconnects. I did not add any tests for this at this time as I just want to get the fix out. --- mopidy/backends/spotify/library.py | 4 +++- mopidy/backends/spotify/session_manager.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mopidy/backends/spotify/library.py b/mopidy/backends/spotify/library.py index a8a9bcd6..96e5f616 100644 --- a/mopidy/backends/spotify/library.py +++ b/mopidy/backends/spotify/library.py @@ -163,7 +163,9 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider): translator.to_mopidy_track(t) for t in results.tracks()]) future.set(search_result) - if not self.backend.spotify.connected.wait(settings.SPOTIFY_TIMEOUT): + # Wait always returns None on python 2.6 :/ + self.backend.spotify.connected.wait(settings.SPOTIFY_TIMEOUT) + if not self.backend.spotify.connected.is_set(): logger.debug('Not connected: Spotify search cancelled') return SearchResult(uri='spotify:search') diff --git a/mopidy/backends/spotify/session_manager.py b/mopidy/backends/spotify/session_manager.py index f2631406..8326d7b4 100644 --- a/mopidy/backends/spotify/session_manager.py +++ b/mopidy/backends/spotify/session_manager.py @@ -83,6 +83,7 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager): def logged_out(self, session): """Callback used by pyspotify""" logger.info('Disconnected from Spotify') + self.connected.clear() def metadata_updated(self, session): """Callback used by pyspotify"""