From 8baf813fb6dd8858d85a20c016dffb184686cea1 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 19 Dec 2012 23:31:33 +0100 Subject: [PATCH] spotify: Use SPOTIFY_TIMEOUT in search --- mopidy/backends/spotify/library.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mopidy/backends/spotify/library.py b/mopidy/backends/spotify/library.py index f451a93a..ca6ee92a 100644 --- a/mopidy/backends/spotify/library.py +++ b/mopidy/backends/spotify/library.py @@ -5,6 +5,7 @@ import logging import pykka from spotify import Link, SpotifyError +from mopidy import settings from mopidy.backends import base from mopidy.models import Track @@ -82,18 +83,20 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider): translator.to_mopidy_track(t) for t in results.tracks()] future.set(tracks) - self.backend.spotify.connected.wait() + if not self.backend.spotify.connected.wait(settings.SPOTIFY_TIMEOUT): + logger.debug('Not connected: Spotify search cancelled') + return [] self.backend.spotify.session.search( spotify_query, callback, track_count=100, album_count=0, artist_count=0) - timeout = 10 # TODO Make this a setting try: - return future.get(timeout=timeout) + return future.get(timeout=settings.SPOTIFY_TIMEOUT) except pykka.Timeout: logger.debug( - 'Timeout: Spotify search did not return in %ds', timeout) + 'Timeout: Spotify search did not return in %ds', + settings.SPOTIFY_TIMEOUT) return [] def _get_all_tracks(self):