How to use the gunicorn.app.base function in gunicorn

To help you get started, we’ve selected a few gunicorn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benoitc / gunicorn / tests / test_arbiter.py View on Github external
# -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

import os
import unittest.mock as mock

import gunicorn.app.base
import gunicorn.arbiter
from gunicorn.config import ReusePort


class DummyApplication(gunicorn.app.base.BaseApplication):
    """
    Dummy application that has a default configuration.
    """

    def init(self, parser, opts, args):
        """No-op"""

    def load(self):
        """No-op"""

    def load_config(self):
        """No-op"""


@mock.patch('gunicorn.sock.close_sockets')
def test_arbiter_stop_closes_listeners(close_sockets):
github binux / pyspider / pyspider / webui / app.py View on Github external
if ':' in display_hostname:
                display_hostname = '[%s]' % display_hostname
            self.logger.info('webui running on http://%s:%d/', display_hostname, port)

        if use_reloader:
            run_with_reloader(inner)
        else:
            inner()

    def quit(self):
        if hasattr(self, 'server'):
            self.server.shutdown_signal = True
        self.logger.info('webui exiting...')


class GunicornApplication(gunicorn.app.base.Application):
    def __init__(self, app, options=None):
        self.options = options or {}
        self.application = app
        super(GunicornApplication, self).__init__()

    def load_config(self):
        pass

    def init(self, parser, opts, args):
        config = dict([(key, value) for key, value in self.options.iteritems()
                       if key in self.cfg.settings and value is not None])
        for key, value in config.iteritems():
            self.cfg.set(key.lower(), value)

    def load(self):
        return self.application
github joshkunz / tumblr2rss / tumblr2rss / tumblr2rss.py View on Github external
app.secret_key = cfg["secret_key"]

def load_oauth_config(oauth, cfg):
    oauth.register(
        name="tumblr",
        client_id=cfg["consumer_key"],
        client_secret=cfg["consumer_secret"],
        request_token_url="https://www.tumblr.com/oauth/request_token",
        access_token_url="https://www.tumblr.com/oauth/access_token",
        authorize_url="http://www.tumblr.com/oauth/authorize",
        api_base_url="https://api.tumblr.com/v2/",
        save_request_token=SessionOAuthCache.save,
        fetch_request_token=SessionOAuthCache.fetch,
    )

class Server(gunicorn_base.BaseApplication):

    def __init__(self, app, options=None):
        self.options = options or {}
        self.application = app
        super(Server, self).__init__()

    def load_config(self):
        config = dict([(key, value) for key, value in self.options.items()
                       if key in self.cfg.settings and value is not None])
        for key, value in config.items():
            self.cfg.set(key.lower(), value)

    def load(self):
        return self.application
github cloudera / hue / desktop / core / ext-py / gunicorn-19.9.0 / examples / standalone_app.py View on Github external
def handler_app(environ, start_response):
    response_body = b'Works fine'
    status = '200 OK'

    response_headers = [
        ('Content-Type', 'text/plain'),
    ]

    start_response(status, response_headers)

    return [response_body]


class StandaloneApplication(gunicorn.app.base.BaseApplication):

    def __init__(self, app, options=None):
        self.options = options or {}
        self.application = app
        super(StandaloneApplication, self).__init__()

    def load_config(self):
        config = dict([(key, value) for key, value in iteritems(self.options)
                       if key in self.cfg.settings and value is not None])
        for key, value in iteritems(config):
            self.cfg.set(key.lower(), value)

    def load(self):
        return self.application
github aws / sagemaker-rl-container / src / vw-serving / src / vw_serving / serve.py View on Github external
KNOWN_CLI_ARGS = ['-r', '--resources', '-w']

MODEL_DIR = integ.ARTIFACTS_VOLUME


class InferenceCustomerError(CustomerError):
    def public_failure_message(self):
        return self.get_error_summary()


class InferenceAlgorithmError(CustomerError):
    def public_failure_message(self):
        return self.get_error_summary()


class GunicornApplication(gunicorn.app.base.Application):
    """Gunicorn application

    By extending base.Application, this class gets access to configuration via the
    environment variable GUNICORN_CMD_ARGS and command line. This env variable gives the flexibility
    to configure gunicorn per-endpoint.

    See: http://docs.gunicorn.org/en/stable/settings.html

    See: https://code.amazon.com/packages/Gunicorn/blobs/5ea7b077710253db3ed6676525090ec04c05e4b8/--/gunicorn/app/base.py#L158 # noqa: E501
    """

    def __init__(self, app, options=None):
        self.options = options or {}
        self.application = app
        super(GunicornApplication, self).__init__()
github linkedin / iris / src / iris / bin / run_server.py View on Github external
#!/usr/bin/env python

# Copyright (c) LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license.
# See LICENSE in the project root for license information.

import gc
import logging
import sys
import multiprocessing
import gunicorn.app.base
from gunicorn.six import iteritems
import iris
import iris.config


class StandaloneApplication(gunicorn.app.base.BaseApplication):

    def __init__(self, options=None, skip_build_assets=False):
        self.options = options or {}
        self.skip_build_assets = skip_build_assets
        super(StandaloneApplication, self).__init__()

    def load_config(self):
        config = {key: value for key, value in iteritems(self.options)
                  if key in self.cfg.settings and value is not None}
        for key, value in iteritems(config):
            self.cfg.set(key.lower(), value)

    def load(self):
        import iris
        reload(iris)
        reload(iris.config)
github admiralobvious / falcon-boilerplate / run.py View on Github external
import logging
import multiprocessing

import falcon
import gunicorn.app.base

from app import configure, create_app, start
from app.config import settings


class Application(gunicorn.app.base.BaseApplication):
    def __init__(self, app, options=None):
        self.options = options or {}
        self.application = app
        super(Application, self).__init__()

    def load_config(self):
        config = dict(
            [
                (key, value)
                for key, value in self.options.items()
                if key in self.cfg.settings and value is not None
            ]
        )
        for key, value in config.items():
            self.cfg.set(key.lower(), value)