Use Actor.post_start() to do actor setup in the actor's own thread

This commit is contained in:
Stein Magnus Jodal 2011-03-08 23:28:24 +01:00
parent 7f725e8c78
commit 0575d5d3be
6 changed files with 16 additions and 27 deletions

View File

@ -61,7 +61,9 @@ class SpotifyBackend(ThreadingActor, Backend):
self.uri_handlers = [u'spotify:', u'http://open.spotify.com/']
# TODO-PYKKA: Do setup after actor starts?
self.spotify = None
def post_start(self):
self.spotify = self._connect()
def _connect(self):

View File

@ -41,10 +41,7 @@ class LastfmFrontend(ThreadingActor, BaseFrontend):
self.lastfm = None
self.last_start_time = None
# TODO-PYKKA: Do setup after actor starts
self._setup()
def _setup(self):
def post_start(self):
try:
username = settings.LASTFM_USERNAME
password_hash = pylast.md5(settings.LASTFM_PASSWORD)

View File

@ -21,14 +21,12 @@ class MpdFrontend(ThreadingActor, BaseFrontend):
"""
def __init__(self):
# TODO-PYKKA: Do setup after actor starts?
self._thread = None
def post_start(self):
self._thread = MpdThread()
self._thread.start()
def destroy(self):
"""Destroys the MPD server."""
self._thread.destroy()
class MpdThread(BaseThread):
def __init__(self):

View File

@ -25,21 +25,16 @@ class DenonMixer(ThreadingActor, BaseMixer):
- :attr:`mopidy.settings.MIXER_EXT_PORT` -- Example: ``/dev/ttyUSB0``
"""
def __init__(self):
"""
Connects using the serial specifications from Denon's RS-232 Protocol
specification: 9600bps 8N1.
"""
# TODO-PYKKA: Do setup after actor starts?
device = kwargs.get('device', None)
if device:
self._device = device
else:
from serial import Serial
self._device = Serial(port=settings.MIXER_EXT_PORT, timeout=0.2)
def __init__(self, *args, **kwargs):
self._device = kwargs.get('device', None)
self._levels = ['99'] + ["%(#)02d" % {'#': v} for v in range(0, 99)]
self._volume = 0
def post_start(self):
if self._device is None:
from serial import Serial
self._device = Serial(port=settings.MIXER_EXT_PORT, timeout=0.2)
def _get_volume(self):
self._ensure_open_device()
self._device.write('MV?\r')

View File

@ -75,10 +75,7 @@ class NadTalker(ThreadingActor):
def __init__(self):
self._device = None
# TODO-PYKKA: Do after actor starts?
self._setup()
def _setup(self):
def post_start(self):
self._open_connection()
self._set_device_to_known_state()

View File

@ -24,7 +24,7 @@ class GStreamerOutput(ThreadingActor, BaseOutput):
def __init__(self):
self.gst_pipeline = None
# TODO-PYKKA: Run setup after actor starts?
def post_start(self):
self._setup_gstreamer()
def _setup_gstreamer(self):