Last active
December 20, 2015 04:59
-
-
Save iromli/6074491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from flask import Flask | |
from flask.ext.script import Manager | |
from flask.ext.script import Command | |
from gunicorn.app.base import Application | |
FOOBAR = True | |
def create_app(config=None): | |
app = Flask( | |
__name__, | |
instance_path=os.getcwd(), | |
instance_relative_config=True, | |
) | |
app.config.from_object(__name__) | |
if config: | |
app.config.from_pyfile(config) | |
return app | |
manager = Manager(create_app) | |
manager.add_option('-c', dest='config', required=False) | |
class Gunicorn(script.Command): | |
def handle(self, app, *args, **kwargs): | |
class GWSGIApp(Application): | |
def init(self, parser, opts, args): | |
globals, locals = {}, {} | |
if opts.config: | |
execfile(opts.config, globals, locals) | |
cfg = {} | |
for k, v in locals.iteritems(): | |
gunicorn_key = k.lstrip('GUNICORN_').lower() | |
if gunicorn_key in self.cfg.settings and v is not None: | |
cfg[gunicorn_key] = v | |
return cfg | |
def load(self): | |
return app | |
GWSGIApp().run() | |
def main(): | |
manager.add_command('run-gunicorn', Gunicorn()) | |
manager.run() | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FOOBAR = False | |
GUNICORN_WORKER_CLASS = 'gevent' | |
GUNICORN_WORKERS = 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment