Skip to content

Instantly share code, notes, and snippets.

@hktonylee hktonylee/
Last active Dec 19, 2018

What would you like to do?
Flask + + gunicorn + auto-reload + Flask-Sockets + anything you can do with gunicorn script
import os
import sys
import subprocess
from flask_migrate import MigrateCommand
from flask_script import Manager, Command, Option
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(BASE_DIR, 'src'))
# Originally from
class GunicornServer(Command):
"""Run the app within Gunicorn"""
def get_options(self):
from gunicorn.config import make_settings
settings = make_settings()
options = []
for setting, klass in settings.items():
if klass.cli:
if klass.const is not None:
options.append(Option(*klass.cli, const=klass.const, action=klass.action))
options.append(Option(*klass.cli, action=klass.action))
return options
def run(self, *args, **kwargs):
run_args = sys.argv[2:]
# !!!!! Change your app here !!!!!
run_args.extend(['-k', 'flask_sockets.worker'])
subprocess.Popen([os.path.join(os.path.dirname(sys.executable), 'gunicorn')] + run_args).wait()
# !!!!! Change your app here !!!!!
from server.gui_server import app
manager = Manager(app)
manager.add_command('db', MigrateCommand)
manager.add_command('runserver', GunicornServer)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.