Skip to content

Instantly share code, notes, and snippets.

@mattions
Created December 18, 2013 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattions/8026970 to your computer and use it in GitHub Desktop.
Save mattions/8026970 to your computer and use it in GitHub Desktop.
quick embedded Gunicorn app
from gunicorn.app.base import Application, Config
class GUnicornFlaskApplication(Application):
def __init__(self, app):
self.usage, self.callable, self.prog, self.app = None, None, None, app
def run(self, **options):
self.cfg = Config()
[self.cfg.set(key, value) for key, value in options.items()]
return Application.run(self)
load = lambda self:self.app
def app(environ, start_response):
data = "Hello, World!\n"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter(data)
if __name__ == "__main__":
gunicorn_app = GUnicornFlaskApplication(app)
gunicorn_app.run(
worker_class="gevent",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment