当前位置: 首页>>代码示例>>Python>>正文


Python Importer.error_handler方法代码示例

本文整理汇总了Python中thumbor.importer.Importer.error_handler方法的典型用法代码示例。如果您正苦于以下问题:Python Importer.error_handler方法的具体用法?Python Importer.error_handler怎么用?Python Importer.error_handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thumbor.importer.Importer的用法示例。


在下文中一共展示了Importer.error_handler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from thumbor.importer import Importer [as 别名]
# 或者: from thumbor.importer.Importer import error_handler [as 别名]
def main(arguments=None):
    """Runs thumbor server with the specified arguments."""

    server_parameters = get_server_parameters(arguments)

    lookup_paths = [os.curdir, expanduser("~"), "/etc/", dirname(__file__)]

    config = Config.load(
        server_parameters.config_path,
        conf_name="thumbor.conf",
        lookup_paths=lookup_paths,
    )

    logging.basicConfig(
        level=getattr(logging, server_parameters.log_level.upper()),
        format=config.THUMBOR_LOG_FORMAT,
        datefmt=config.THUMBOR_LOG_DATE_FORMAT,
    )

    importer = Importer(config)
    importer.import_modules()

    if importer.error_handler_class is not None:
        importer.error_handler = importer.error_handler_class(config)

    if server_parameters.security_key is None:
        server_parameters.security_key = config.SECURITY_KEY

    if not isinstance(server_parameters.security_key, basestring):
        raise RuntimeError(
            "No security key was found for this instance of thumbor. "
            + "Please provide one using the conf file or a security key file."
        )

    context = Context(server=server_parameters, config=config, importer=importer)

    application = importer.import_class(server_parameters.app_class)(context)

    server = HTTPServer(application)

    if context.server.fd is not None:
        fd_number = get_as_integer(context.server.fd)
        if fd_number is None:
            with open(context.server.fd, "r") as sock:
                fd_number = sock.fileno()

        sock = socket.fromfd(fd_number, socket.AF_UNIX, socket.SOCK_STREAM)
        server.add_socket(sock)
    else:
        server.bind(context.server.port, context.server.ip)

    server.start(1)

    try:
        logging.debug(
            "thumbor running at %s:%d" % (context.server.ip, context.server.port)
        )
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        print("-- thumbor closed by user interruption --")
开发者ID:mrluanma,项目名称:thumbor-heroku,代码行数:62,代码来源:server.py

示例2: get_importer

# 需要导入模块: from thumbor.importer import Importer [as 别名]
# 或者: from thumbor.importer.Importer import error_handler [as 别名]
def get_importer(config):
    importer = Importer(config)
    importer.import_modules()

    if importer.error_handler_class is not None:
        importer.error_handler = importer.error_handler_class(config)

    return importer
开发者ID:beenanner,项目名称:thumbor,代码行数:10,代码来源:server.py

示例3: main

# 需要导入模块: from thumbor.importer import Importer [as 别名]
# 或者: from thumbor.importer.Importer import error_handler [as 别名]
def main(arguments=None):
    '''Runs thumbor server with the specified arguments.'''

    server_parameters = get_server_parameters(arguments)

    lookup_paths = [os.curdir,
                    expanduser('~'),
                    '/etc/',
                    dirname(__file__)]

    config = Config.load(server_parameters.config_path, conf_name='thumbor.conf', lookup_paths=lookup_paths)

    logging.basicConfig(
        level=getattr(logging, server_parameters.log_level.upper()),
        format=config.THUMBOR_LOG_FORMAT,
        datefmt=config.THUMBOR_LOG_DATE_FORMAT
    )

    importer = Importer(config)
    importer.import_modules()

    if importer.error_handler_class is not None:
        importer.error_handler = importer.error_handler_class(config)

    if server_parameters.security_key is None:
        server_parameters.security_key = config.SECURITY_KEY

    if not isinstance(server_parameters.security_key, basestring):
        raise RuntimeError(
            'No security key was found for this instance of thumbor. ' +
            'Please provide one using the conf file or a security key file.')

    context = Context(server=server_parameters, config=config, importer=importer)

    application = importer.import_class(server_parameters.app_class)(context)

    server = HTTPServer(application)

    if context.server.fd is not None:
        sock = socket.fromfd(context.server.fd,
                             socket.AF_INET | socket.AF_INET6,
                             socket.SOCK_STREAM)
        server.add_socket(sock)
    else:
        server.bind(context.server.port, context.server.ip)

    server.start(1)

    try:
        logging.debug('thumbor running at %s:%d' % (context.server.ip, context.server.port))
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        print
        print "-- thumbor closed by user interruption --"
开发者ID:HyperionGG,项目名称:thumbor,代码行数:56,代码来源:server.py

示例4: main

# 需要导入模块: from thumbor.importer import Importer [as 别名]
# 或者: from thumbor.importer.Importer import error_handler [as 别名]
def main(arguments=None):  # NOQA
    '''Runs thumbor server with the specified arguments.'''

    server_parameters = get_server_parameters(arguments)

    lookup_paths = [os.curdir,
                    expanduser('~'),
                    '/etc/',
                    dirname(__file__)]

    config = Config.load(server_parameters.config_path, conf_name='thumbor.conf', lookup_paths=lookup_paths)

    if (config.THUMBOR_LOG_CONFIG and config.THUMBOR_LOG_CONFIG != ''):
        logging.config.dictConfig(config.THUMBOR_LOG_CONFIG)
    else:
        logging.basicConfig(
            level=getattr(logging, server_parameters.log_level.upper()),
            format=config.THUMBOR_LOG_FORMAT,
            datefmt=config.THUMBOR_LOG_DATE_FORMAT
        )

    importer = Importer(config)
    importer.import_modules()

    if importer.error_handler_class is not None:
        importer.error_handler = importer.error_handler_class(config)

    if server_parameters.security_key is None:
        server_parameters.security_key = config.SECURITY_KEY

    if not isinstance(server_parameters.security_key, basestring):
        raise RuntimeError(
            'No security key was found for this instance of thumbor. ' +
            'Please provide one using the conf file or a security key file.')

    if config.USE_GIFSICLE_ENGINE:
        server_parameters.gifsicle_path = which('gifsicle')
        if server_parameters.gifsicle_path is None:
            raise RuntimeError(
                'If using USE_GIFSICLE_ENGINE configuration to True, the `gifsicle` binary must be in the PATH '
                'and must be an executable.'
            )

    context = Context(
        server=server_parameters,
        config=config,
        importer=importer
    )

    application = importer.import_class(server_parameters.app_class)(context)

    server = HTTPServer(application)

    if context.server.fd is not None:
        fd_number = get_as_integer(context.server.fd)
        if fd_number is None:
            with open(context.server.fd, 'r') as sock:
                fd_number = sock.fileno()

        sock = socket.fromfd(fd_number,
                             socket.AF_INET | socket.AF_INET6,
                             socket.SOCK_STREAM)
        server.add_socket(sock)
    else:
        server.bind(context.server.port, context.server.ip)

    server.start(1)

    try:
        logging.debug('thumbor running at %s:%d' % (context.server.ip, context.server.port))
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        print
        print "-- thumbor closed by user interruption --"
    finally:
        context.thread_pool.cleanup()
开发者ID:riseofthetigers,项目名称:thumbor,代码行数:78,代码来源:server.py

示例5: main

# 需要导入模块: from thumbor.importer import Importer [as 别名]
# 或者: from thumbor.importer.Importer import error_handler [as 别名]
def main(arguments=None):
    '''Runs thumbor server with the specified arguments.'''

    server_parameters = get_server_parameters(arguments)

    lookup_paths = [os.curdir,
                    expanduser('~'),
                    '/etc/',
                    dirname(__file__)]

    config = Config.load(server_parameters.config_path, conf_name='thumbor.conf', lookup_paths=lookup_paths)

    if (config.THUMBOR_LOG_CONFIG and config.THUMBOR_LOG_CONFIG != '') :
      logging.config.dictConfig(config.THUMBOR_LOG_CONFIG)
    else:
      logging.basicConfig(
          level=getattr(logging, server_parameters.log_level.upper()),
          format=config.THUMBOR_LOG_FORMAT,
          datefmt=config.THUMBOR_LOG_DATE_FORMAT,
          filename=server_parameters.log_file
      )

    importer = Importer(config)
    importer.import_modules()

    if importer.error_handler_class is not None:
        importer.error_handler = importer.error_handler_class(config)

    if server_parameters.security_key is None:
        server_parameters.security_key = config.SECURITY_KEY

    if not isinstance(server_parameters.security_key, basestring):
        raise RuntimeError(
            'No security key was found for this instance of thumbor. ' +
            'Please provide one using the conf file or a security key file.')

    if config.USE_GIFSICLE_ENGINE:
        server_parameters.gifsicle_path = which('gifsicle')
        if server_parameters.gifsicle_path is None:
            raise RuntimeError('If using USE_GIFSICLE_ENGINE configuration to True, the `gifsicle` binary must be in the PATH and must be an executable.')

    context = Context(
        server=server_parameters,
        config=config,
        importer=importer
    )


    application = importer.import_class(server_parameters.app_class)(context)

    server = HTTPServer(application)

    if context.server.fd is not None:
        fd_number = get_as_integer(context.server.fd)
        if fd_number is None:
            with open(context.server.fd, 'r') as sock:
                fd_number = sock.fileno()

        sock = socket.fromfd(fd_number,
                             socket.AF_INET | socket.AF_INET6,
                             socket.SOCK_STREAM)
        server.add_socket(sock)
    else:
        server.bind(context.server.port, context.server.ip)

    server.start(1)

    # Adapted from gist.github.com/mywaiting/4643396.  Note: This function is
    # only ever executed as a callback by the main IO loop.  Therefore all
    # calls to it are guaranteed to be serialized, so it doesn't have to be
    # either thread-safe or reentrant.
    global shutting_down
    shutting_down = False
    def shutdown():
        global shutting_down
        if shutting_down:
            return
        shutting_down = True
        logging.critical('Stopping server. No longer accepting connections')
        server.stop()
        logging.critical('Shutdown in at most %d seconds',
                         config.MAX_WAIT_BEFORE_SHUTDOWN)
        io_loop = tornado.ioloop.IOLoop.instance()
        deadline = time.time() + config.MAX_WAIT_BEFORE_SHUTDOWN
        def stop_loop():
            now = time.time()
            if now < deadline and (io_loop._callbacks or io_loop._timeouts):
                io_loop.add_timeout(min(now + 1, deadline), stop_loop)
            else:
                logging.critical('Stopping IO loop and exiting')
                io_loop.stop()
        stop_loop()

    def sig_handler(sig, frame):
        # Stdlib Logging functions are not reentrant.
        # logging.warning('Caught signal: %s', sig)
        tornado.ioloop.IOLoop.instance().add_callback_from_signal(shutdown)
    signal.signal(signal.SIGTERM, sig_handler)
    signal.signal(signal.SIGINT, sig_handler)

#.........这里部分代码省略.........
开发者ID:food52,项目名称:thumbor,代码行数:103,代码来源:server.py


注:本文中的thumbor.importer.Importer.error_handler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。