Skip to content
Browse files

Merge pull request #108 from jodal/feature/clean-early-shutdown

feature/clean-early-shutdown
  • Loading branch information...
2 parents c0a39af + 8e983c3 commit e6652f0a0aed5341e68ed1392472debb5327eff7 @adamcik adamcik committed Jun 11, 2011
Showing with 26 additions and 9 deletions.
  1. +6 −3 mopidy/backends/spotify/__init__.py
  2. +7 −3 mopidy/core.py
  3. +1 −1 mopidy/gstreamer.py
  4. +12 −2 mopidy/utils/process.py
View
9 mopidy/backends/spotify/__init__.py
@@ -72,19 +72,22 @@ def __init__(self, *args, **kwargs):
self.gstreamer = None
self.spotify = None
+ # Fail early if settings are not present
+ self.username = settings.SPOTIFY_USERNAME
+ self.password = settings.SPOTIFY_PASSWORD
+
def on_start(self):
gstreamer_refs = ActorRegistry.get_by_class(GStreamer)
assert len(gstreamer_refs) == 1, 'Expected exactly one running gstreamer.'
self.gstreamer = gstreamer_refs[0].proxy()
+ logger.info(u'Mopidy uses SPOTIFY(R) CORE')
self.spotify = self._connect()
def _connect(self):
from .session_manager import SpotifySessionManager
- logger.info(u'Mopidy uses SPOTIFY(R) CORE')
logger.debug(u'Connecting to Spotify')
- spotify = SpotifySessionManager(
- settings.SPOTIFY_USERNAME, settings.SPOTIFY_PASSWORD)
+ spotify = SpotifySessionManager(self.username, self.password)
spotify.start()
return spotify
View
10 mopidy/core.py
@@ -40,11 +40,15 @@ def main():
setup_mixer()
setup_backend()
setup_frontends()
- while ActorRegistry.get_all():
+ while True:
time.sleep(1)
- logger.info(u'No actors left. Exiting...')
+ except SettingsError as e:
+ logger.error(e.message)
except KeyboardInterrupt:
- logger.info(u'User interrupt. Exiting...')
+ logger.info(u'Interrupted. Exiting...')
+ except Exception as e:
+ logger.exception(e)
+ finally:
stop_all_actors()
def parse_options():
View
2 mopidy/gstreamer.py
@@ -298,7 +298,7 @@ def connect_output(self, output):
output.sync_state_with_parent() # Required to add to running pipe
gst.element_link_many(self._tee, output)
self._outputs.append(output)
- logger.info('Added %s', output.get_name())
+ logger.debug('GStreamer added %s', output.get_name())
def list_outputs(self):
"""
View
14 mopidy/utils/process.py
@@ -1,5 +1,6 @@
import logging
import signal
+import thread
import threading
import gobject
@@ -12,19 +13,28 @@
logger = logging.getLogger('mopidy.utils.process')
+def exit_process():
+ logger.debug(u'Interrupting main...')
+ thread.interrupt_main()
+ logger.debug(u'Interrupted main')
+
def exit_handler(signum, frame):
"""A :mod:`signal` handler which will exit the program on signal."""
signals = dict((k, v) for v, k in signal.__dict__.iteritems()
if v.startswith('SIG') and not v.startswith('SIG_'))
- logger.info(u'Got %s. Exiting...', signals[signum])
- stop_all_actors()
+ logger.info(u'Got %s signal', signals[signum])
+ exit_process()
def stop_all_actors():
num_actors = len(ActorRegistry.get_all())
while num_actors:
+ logger.debug(u'Seeing %d actor and %d non-actor thread(s): %s',
+ num_actors, threading.active_count() - num_actors,
+ ', '.join([t.name for t in threading.enumerate()]))
logger.debug(u'Stopping %d actor(s)...', num_actors)
ActorRegistry.stop_all()
num_actors = len(ActorRegistry.get_all())
+ logger.debug(u'All actors stopped.')
class BaseThread(threading.Thread):
def __init__(self):

0 comments on commit e6652f0

Please sign in to comment.
Something went wrong with that request. Please try again.