import logging
import multiprocessing
import optparse

from mopidy import get_version, settings
from mopidy.utils import get_class
from mopidy.utils.log import setup_logging
from mopidy.utils.path import get_or_create_folder, get_or_create_file
from mopidy.utils.process import BaseProcess
from mopidy.utils.settings import list_settings_optparse_callback

logger = logging.getLogger('mopidy.core')

class CoreProcess(BaseProcess):
    def __init__(self):
        super(CoreProcess, self).__init__(name='CoreProcess')
        self.core_queue = multiprocessing.Queue()
        self.options = self.parse_options()
        self.output = None
        self.backend = None
        self.frontend = None

    def parse_options(self):
        parser = optparse.OptionParser(version='Mopidy %s' % get_version())
        parser.add_option('-q', '--quiet',
            action='store_const', const=0, dest='verbosity_level',
            help='less output (warning level)')
        parser.add_option('-v', '--verbose',
            action='store_const', const=2, dest='verbosity_level',
            help='more output (debug level)')
        parser.add_option('--dump',
            action='store_true', dest='dump',
            help='dump debug log to file')
        parser.add_option('--list-settings',
            action='callback', callback=list_settings_optparse_callback,
            help='list current settings')
        return parser.parse_args()[0]

    def run_inside_try(self):
        logger.info(u'-- Starting Mopidy --')
        self.setup()
        while True:
            message = self.core_queue.get()
            self.process_message(message)

    def setup(self):
        self.setup_logging()
        self.setup_settings()
        self.output = self.setup_output(self.core_queue)
        self.backend = self.setup_backend(self.core_queue, self.output)
        self.frontend = self.setup_frontend(self.core_queue, self.backend)

    def setup_logging(self):
        setup_logging(self.options.verbosity_level, self.options.dump)

    def setup_settings(self):
        get_or_create_folder('~/.mopidy/')
        get_or_create_file('~/.mopidy/settings.py')
        settings.validate()

    def setup_output(self, core_queue):
        output = get_class(settings.OUTPUT)(core_queue)
        output.start()
        return output

    def setup_backend(self, core_queue, output):
        return get_class(settings.BACKENDS[0])(core_queue, output)

    def setup_frontend(self, core_queue, backend):
        frontend = get_class(settings.FRONTENDS[0])(core_queue, backend)
        frontend.start()
        return frontend

    def process_message(self, message):
        if message.get('to') == 'output':
            self.output.process_message(message)
        elif message.get('to') == 'frontend':
            self.frontend.process_message(message)
        elif message['command'] == 'end_of_track':
            self.backend.playback.on_end_of_track()
        elif message['command'] == 'stop_playback':
            self.backend.playback.stop()
        elif message['command'] == 'set_stored_playlists':
            self.backend.stored_playlists.playlists = message['playlists']
        else:
            logger.warning(u'Cannot handle message: %s', message)

@@ -681,23 +681,22 @@
 frontend
+s
  = 
-None
+%5B%5D
 %0A%0A    de
@@ -1868,16 +1868,17 @@
 frontend
+s
  = self.
@@ -1887,24 +1887,25 @@
 tup_frontend
+s
 (self.core_q
@@ -2461,16 +2461,17 @@
 frontend
+s
 (self, c
@@ -2511,42 +2511,122 @@
 tend
+s
  = 
-get_class(settings.FRONTENDS%5B0%5D
+%5B%5D%0A        for frontend_class_name in settings.FRONTENDS:%0A            frontend = get_class(frontend_class_name
 )(co
@@ -2644,32 +2644,36 @@
 ackend)%0A        
+  
+  
 frontend.start()
@@ -2665,32 +2665,71 @@
 rontend.start()%0A
+            frontends.append(frontend)%0A
         return f
@@ -2735,16 +2735,17 @@
 frontend
+s
 %0A%0A    de
@@ -2919,37 +2919,80 @@
 d':%0A            
-self.
+for frontend in self.frontends:%0A                
 frontend.process

Update CoreProcess to handle multiple frontends