Python gunicorn.app.base 模块,BaseApplication() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用gunicorn.app.base.BaseApplication()

项目:makiki    作者:faith0811    | 项目源码 | 文件源码
def dev_run(args):
    try:
        from gunicorn_config import import_wsgi
    except ImportError:
        raise ImportError('Must run inside a Makiki app and keep gunicorn_config file untouched.')

    class DevServer(BaseApplication):
        def __init__(self, bind, workers):
            self._bind = bind
            self._workers = workers
            super().__init__()

        def load_config(self):
            self.cfg.set('bind', self._bind)
            self.cfg.set('workers', self._workers)
            self.cfg.set('worker_class', 'gevent')
            self.cfg.set('reload', True)

        def load(self):
            return import_wsgi()

    DevServer(args.bind, args.workers).run()
项目:combine    作者:llllllllll    | 项目源码 | 文件源码
def build_app(model_cache_dir,
              token_secret,
              client,
              bot_user,
              github_url,
              email_address,
              gunicorn_options):
    """Build the app object.

    Parameters
    ----------
    model_cache_dir : path-like
        The path to the model directory.
    token_secret : bytes
        The shared secret for the uploader and irc server.
    client : Library
        The client used to fetch beatmaps.
    bot_user : str
        The username of the bot.
    github_url : str
        The url of the repo on github.
    email_address : str
        The email address for support / comments.
    gunicorn_options : dict
        Options to forward to gunicorn.

    Returns
    -------
    app : App
        The app to run.
    """
    inner_app = flask.Flask(__name__)
    inner_app.register_blueprint(
        api,
        model_cache_dir=pathlib.Path(model_cache_dir),
        token_secret=Fernet(token_secret),
        client=client,
        bot_user=bot_user,
        github_url=github_url,
        email_address=email_address,
    )

    class app(BaseApplication):
        def load(self):
            return inner_app

        def load_config(self, *, _cfg=gunicorn_options):
            for k, v in _cfg.items():
                k = k.lower()
                if k in self.cfg.settings and v is not None:
                    self.cfg.set(k.lower(), v)

    return app()