Created
May 19, 2019 22:43
-
-
Save mehmetg/0304bf1e349ff1bc4a5bf005d806effd to your computer and use it in GitHub Desktop.
Wraps a dash application into a 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
import gunicorn.app.base | |
from gunicorn.six import iteritems | |
class DashGunicornWrapper(gunicorn.app.base.BaseApplication): | |
def __init__(self, app, options=None): | |
self.options = options or {} | |
self.application = app.server | |
super(DashGunicornWrapper, 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 | |
if __name__ == '__main__': | |
workers = 4 | |
bind = "{host}:{port}".format(host='127.0.0.1', port=8080) | |
options = { | |
'bind': bind, | |
'debug': True, | |
'workers': workers | |
} | |
print(options) | |
DashGunicornWrapper(app=app, options=options).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment