def make_http_server(self): multiprocessing = False if settings['PROCESSES'] and settings['PROCESSES'] > 1: if settings['DEBUG']: app_log.info('Multiprocess could not be used in debug mode') else: multiprocessing = True if self.io_loop: if not self.io_loop.initialized(): # this means self.io_loop is a customized io_loop, so `install` should be called # to make it the singleton instance #print self.io_loop.__class__.__name__ self.io_loop.install() else: # NOTE To support running tornado for multiple processes, we do not instance ioloop if multiprocessing is True if not multiprocessing: self.io_loop = IOLoop.instance() http_server_options = self.get_httpserver_options() http_server = HTTPServer(self.application, io_loop=self.io_loop, **http_server_options) listen_kwargs = {} if settings.get('ADDRESS'): listen_kwargs['address'] = settings.get('ADDRESS') if multiprocessing: # Multiprocessing mode try: http_server.bind(settings['PORT'], **listen_kwargs) except socket.error, e: app_log.warning('socket.error detected on http_server.listen, set ADDRESS="0.0.0.0" in settings to avoid this problem') raise e http_server.start(settings['PROCESSES'])
def _init_infrastructures(self): multiprocessing = False if settings['PROCESSES'] and settings['PROCESSES'] > 1: if settings['DEBUG']: app_log.info('Multiprocess could not be used in debug mode') else: multiprocessing = True if self.io_loop: if not self.io_loop.initialized(): # this means self.io_loop is a customized io_loop, so `install` should be called # to make it the singleton instance #print self.io_loop.__class__.__name__ self.io_loop.install() else: # NOTE To support running tornado for multiple processes, we do not instance ioloop if multiprocessing is True if not multiprocessing: self.io_loop = IOLoop.instance() application = self._make_application() http_server_options = self.get_httpserver_options() http_server = HTTPServer(application, io_loop=self.io_loop, **http_server_options) listen_kwargs = {} if settings.get('ADDRESS'): listen_kwargs['address'] = settings.get('ADDRESS') if multiprocessing: # Multiprocessing mode try: http_server.bind(settings['PORT'], **listen_kwargs) except socket.error, e: app_log.warning('socket.error detected on http_server.listen, set ADDRESS="0.0.0.0" in settings to avoid this problem') raise e http_server.start(settings['PROCESSES'])
def _exception_default_handler(self, e): """This method is a copy of tornado.web.RequestHandler._handle_request_exception """ if isinstance(e, HTTPError): if e.log_message: format = "%d %s: " + e.log_message args = [e.status_code, self._request_summary()] + list(e.args) app_log.warning(format, *args) if e.status_code not in httplib.responses: app_log.error("Bad HTTP status code: %d", e.status_code) self.send_error(500, exc_info=sys.exc_info()) else: self.send_error(e.status_code, exc_info=sys.exc_info()) else: app_log.error("Uncaught exception %s\n%r", self._request_summary(), self.request, exc_info=True) self.send_error(500, exc_info=sys.exc_info())
# Multiprocessing mode try: http_server.bind(settings['PORT'], **listen_kwargs) except socket.error, e: app_log.warning( 'socket.error detected on http_server.listen, set ADDRESS="0.0.0.0" in settings to avoid this problem' ) raise e http_server.start(settings['PROCESSES']) else: # Single process mode try: http_server.listen(settings['PORT'], **listen_kwargs) except socket.error, e: app_log.warning( 'socket.error detected on http_server.listen, set ADDRESS="0.0.0.0" in settings to avoid this problem' ) raise e self.http_server = http_server @property def is_running(self): if self.io_loop: return self.io_loop._running return False def _instance_ioloop(self): if not self.io_loop: self.io_loop = IOLoop.instance()
listen_kwargs['address'] = settings.get('ADDRESS') if multiprocessing: # Multiprocessing mode try: http_server.bind(settings['PORT'], **listen_kwargs) except socket.error, e: app_log.warning('socket.error detected on http_server.listen, set ADDRESS="0.0.0.0" in settings to avoid this problem') raise e http_server.start(settings['PROCESSES']) else: # Single process mode try: http_server.listen(settings['PORT'], **listen_kwargs) except socket.error, e: app_log.warning('socket.error detected on http_server.listen, set ADDRESS="0.0.0.0" in settings to avoid this problem') raise e self.http_server = http_server self.application = application @property def is_running(self): if self.io_loop: return self.io_loop._running return False def _instance_ioloop(self): if not self.io_loop: self.io_loop = IOLoop.instance()