Exemple #1
0
def _log_options():
    if tornado.version_info < (3, 0, 0, 0):
        for key, option in options.iteritems():
            gen_logger.info('Options: (%s, %s)', key, option.value())
    else:
        for key, option in options.items():
            gen_logger.info('Options: (%s, %s)', key, option)
Exemple #2
0
def _log_options():
    if tornado.version_info < (3, 0, 0, 0):
        for key, option in options.iteritems():
            gen_logger.info('Options: (%s, %s)', key, option.value())
    else:
        for key, option in options.items():
            gen_logger.info('Options: (%s, %s)', key, option)
Exemple #3
0
def _quit():
    if not tornado.ioloop.IOLoop.instance()._running:
        return

    CommonTimer().stop()
    HTTPServer().stop()
    tornado.ioloop.IOLoop.instance().stop()
    tornado.ioloop.IOLoop.instance().close(all_fds=True)

    gen_logger.info('STOP TORNADO SERVER ...')
Exemple #4
0
def _quit():
    if not tornado.ioloop.IOLoop.instance().running():
        return

    CommonTimer().stop()
    HTTPServer().stop()
    tornado.ioloop.IOLoop.instance().stop()
    tornado.ioloop.IOLoop.instance().close(all_fds=True)

    gen_logger.info('STOP TORNADO SERVER ...')
Exemple #5
0
def main():
    """main function
    """
    setup_options()

    app_name = 'twork'

    web_handlers = None
    timer_callback = None
    app_info = None
    settings = {}
    if options.app_module is not None:
        try:
            _module = import_object(options.app_module)

            web_handlers = _module.HANDLERS
            app_name = _module.APP_INFO.lower()
            app_info = _module.APP_INFO.upper()
            settings = _module.SETTINGS

            _module.setup()

            timer_callback = _module.timer_callback
            if options.timer_start:
                CommonTimer().start(timer_callback)
        except (ImportError, AttributeError) as e:
            gen_logger.error(e, exc_info=True)

    twork.utils.common.define_process_title('twork::{0}#{1}'.format(
        app_name, options.env))

    setup_log()

    _setup_signal()

    _log_options()

    gen_logger.info('START TORNADO SERVER ...')

    try:
        HTTPServer().start(web_handlers, app_info=app_info, **settings)

        tornado.ioloop.IOLoop.instance().start()
    except Exception as e:
        gen_logger.error('UnCaught Exception: %s', e, exc_info=True)
    finally:
        _quit()
Exemple #6
0
def main():
    """main function
    """
    setup_options()
    setup_log()
    _setup_signal()

    gen_logger.info('START TORNADO SERVER ...')

    app_name = 'twork'

    web_handlers   = None
    app_info       = None
    settings       = {}
    _module        = None
    if options.app_module is not None:
        try:
            _module = import_object(options.app_module)

            web_handlers = _module.HANDLERS
            app_name = _module.APP_INFO.lower()
            app_info = _module.APP_INFO.upper()
            settings = _module.SETTINGS
        except (ImportError, AttributeError) as e:
            gen_logger.error(e, exc_info=True)

    setup_options()
    _log_options()

    twork.utils.common.define_process_title('twork::{0}#{1}'.
            format(app_name, options.env))

    try:
        HTTPServer().start(web_handlers, app_info=app_info,
                twork_module=_module,
                **settings)

        _setup_cpu_affinity()

        tornado.ioloop.IOLoop.instance().start()
    except Exception as e:
        gen_logger.error('UnCaught Exception: %s', e, exc_info=True)
    finally:
        _quit()