コード例 #1
0
ファイル: wsgi.py プロジェクト: ckwang8128/baseplate
def make_server(server_config, listener, app):
    """Make a gevent server for WSGI apps."""
    # pylint: disable=maybe-no-member
    cfg = config.parse_config(
        server_config,
        {
            "handler": config.Optional(config.String, default=None),
            "max_concurrency": config.Integer,
            "stop_timeout": config.Optional(config.Integer, default=0),
        },
    )

    pool = Pool(size=cfg.max_concurrency)
    log = LoggingLogAdapter(logger, level=logging.DEBUG)

    kwargs = {}
    if gevent.version_info[:2] >= (1, 1):  # error_log is new in 1.1
        kwargs["error_log"] = LoggingLogAdapter(logger, level=logging.ERROR)

    if cfg.handler:
        kwargs["handler_class"] = _load_factory(cfg.handler, default_name=None)

    server = WSGIServer(listener, application=app, spawn=pool, log=log, **kwargs)
    server.stop_timeout = cfg.stop_timeout

    runtime_monitor.start(server_config, app, pool)
    return server
コード例 #2
0
ファイル: wsgi.py プロジェクト: suversky/baseplate.py
def make_server(server_config: Dict[str, str], listener: socket.socket,
                app: Any) -> StreamServer:
    """Make a gevent server for WSGI apps."""
    # pylint: disable=maybe-no-member
    cfg = config.parse_config(
        server_config,
        {
            "handler": config.Optional(config.String, default=None),
            "max_concurrency": config.Integer,
            "stop_timeout": config.Optional(config.Integer, default=0),
        },
    )

    pool = Pool(size=cfg.max_concurrency)
    log = LoggingLogAdapter(logger, level=logging.DEBUG)

    kwargs: Dict[str, Any] = {}
    if cfg.handler:
        kwargs["handler_class"] = _load_factory(cfg.handler, default_name=None)

    server = WSGIServer(
        listener,
        application=app,
        spawn=pool,
        log=log,
        error_log=LoggingLogAdapter(logger, level=logging.ERROR),
        **kwargs,
    )
    server.stop_timeout = cfg.stop_timeout

    runtime_monitor.start(server_config, app, pool)
    return server
コード例 #3
0
ファイル: wsgi.py プロジェクト: wlwanpan/baseplate.py
def make_server(server_config: Dict[str, str], listener: socket.socket,
                app: Any) -> StreamServer:
    """Make a gevent server for WSGI apps."""
    # pylint: disable=maybe-no-member
    cfg = config.parse_config(
        server_config,
        {
            "handler":
            config.Optional(config.String, default=None),
            "max_concurrency":
            config.Optional(config.Integer),
            "stop_timeout":
            config.Optional(config.TimespanWithLegacyFallback,
                            default=datetime.timedelta(seconds=10)),
        },
    )

    if cfg.max_concurrency is not None:
        raise Exception(
            "The max_concurrency setting is not allowed for WSGI servers. See https://git.io/Jeywc."
        )

    pool = Pool()
    log = LoggingLogAdapter(logger, level=logging.DEBUG)

    kwargs: Dict[str, Any] = {}
    if cfg.handler:
        kwargs["handler_class"] = _load_factory(cfg.handler, default_name=None)

    server = WSGIServer(
        listener,
        application=app,
        spawn=pool,
        log=log,
        error_log=LoggingLogAdapter(logger, level=logging.ERROR),
        **kwargs,
    )
    server.stop_timeout = cfg.stop_timeout.total_seconds()

    runtime_monitor.start(server_config, app, pool)
    return server
コード例 #4
0
ファイル: server_tests.py プロジェクト: ckwang8128/baseplate
    def test_default_name(self, import_module):
        factory = server._load_factory("package.module", "default_name")

        self.assertEqual(import_module.call_args, mock.call("package.module"))
        self.assertEqual(factory, import_module.return_value.default_name)
コード例 #5
0
ファイル: server_tests.py プロジェクト: fizx/baseplate.py
    def test_default_name(self, import_module):
        factory = server._load_factory("package.module", "default_name")

        self.assertEqual(import_module.call_args, mock.call("package.module"))
        self.assertEqual(factory, import_module.return_value.default_name)