From a2ec5ff5b44d22cba5992128802b4334ba407ffe Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 15 Feb 2010 22:59:29 +0100 Subject: [PATCH] Switch from time.sleep to threading.Event for making search non-async --- mopidy/backends/libspotify.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mopidy/backends/libspotify.py b/mopidy/backends/libspotify.py index b27333fd..1e11a261 100644 --- a/mopidy/backends/libspotify.py +++ b/mopidy/backends/libspotify.py @@ -42,21 +42,22 @@ class LibspotifyCurrentPlaylistController(BaseCurrentPlaylistController): class LibspotifyLibraryController(BaseLibraryController): - search_results = False + _search_results = None + _search_results_received = threading.Event() def search(self, type, what): - # XXX This is slow - self.search_results = None + # FIXME This is slow, like 12-14s between querying and getting results + self._search_results_received.clear() + query = u'%s:%s' % (type, what) def callback(results, userdata): logger.debug(u'Search results received') - self.search_results = results - query = u'%s:%s' % (type, what) + self._search_results = results + self._search_results_received.set() self.backend.spotify.search(query.encode(ENCODING), callback) - while self.search_results is None: - time.sleep(0.01) + self._search_results_received.wait() result = Playlist(tracks=[self.backend.translate.to_mopidy_track(t) - for t in self.search_results.tracks()]) - self.search_results = False + for t in self._search_results.tracks()]) + self._search_results = None return result