Skip to content

Instantly share code, notes, and snippets.

@mehmetg
Created May 19, 2019 22:43
Show Gist options
  • Save mehmetg/0304bf1e349ff1bc4a5bf005d806effd to your computer and use it in GitHub Desktop.
Save mehmetg/0304bf1e349ff1bc4a5bf005d806effd to your computer and use it in GitHub Desktop.
Wraps a dash application into a gunicorn app.
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