From f9755b562cbedb0d66ca1ea536fda21ec9daeff2 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 16 Jul 2014 22:21:05 +0200 Subject: [PATCH] http: Raise FrontendError if socket creation fails This removes the stacktraces when two Mopidy instances are started with the same hostname/port configuration. --- mopidy/http/actor.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mopidy/http/actor.py b/mopidy/http/actor.py index 96c71c8c..c9272bb6 100644 --- a/mopidy/http/actor.py +++ b/mopidy/http/actor.py @@ -11,10 +11,10 @@ import tornado.ioloop import tornado.web import tornado.websocket -from mopidy import models, zeroconf +from mopidy import exceptions, models, zeroconf from mopidy.core import CoreListener from mopidy.http import handlers -from mopidy.utils import formatting +from mopidy.utils import encoding, formatting logger = logging.getLogger(__name__) @@ -33,7 +33,16 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): self.port = config['http']['port'] self.zeroconf_name = config['http']['zeroconf'] self.zeroconf_service = None - self.app = None + + try: + logger.debug('Starting HTTP server') + self.app = tornado.web.Application(self._get_request_handlers()) + self.app.listen( + self.port, self.hostname if self.hostname != '::' else None) + except IOError as error: + raise exceptions.FrontendError( + 'HTTP server startup failed: %s' % + encoding.locale_decode(error)) def on_start(self): threading.Thread(target=self._startup).start() @@ -44,10 +53,6 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): tornado.ioloop.IOLoop.instance().add_callback(self._shutdown) def _startup(self): - logger.debug('Starting HTTP server') - self.app = tornado.web.Application(self._get_request_handlers()) - self.app.listen(self.port, - self.hostname if self.hostname != '::' else None) logger.info( 'HTTP server running at http://%s:%s', self.hostname, self.port) tornado.ioloop.IOLoop.instance().start()