Created
December 18, 2013 18:07
-
-
Save mattions/8026970 to your computer and use it in GitHub Desktop.
quick embedded Gunicorn app
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
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