Skip to content

Instantly share code, notes, and snippets.

@menghan
Created September 22, 2014 07:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menghan/9a632bbb0acb445f4f3a to your computer and use it in GitHub Desktop.
Save menghan/9a632bbb0acb445f4f3a to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import os
import sys
from flask.ext.script import Command, Option
class GunicornServer(Command):
"""Run the app within Gunicorn"""
def get_options(self):
from gunicorn.config import make_settings
settings = make_settings()
options = (
Option(*klass.cli, action=klass.action)
for setting, klass in settings.iteritems() if klass.cli
)
return options
def run(self, *args, **kwargs):
run_args = sys.argv[2:]
run_args.append('manage:app')
os.execvp('gunicorn', [''] + run_args)
@hktonylee
Copy link

hktonylee commented Jul 14, 2017

This is not working in gunicorn==19.7.1. In line 12, klass.action, because of the settings gunicorn.config.Sendfile is using store_const which has an extra argument const. Sometimes does not work because of that.

The last line of traceback is

  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 1334, in add_argument
    action = action_class(**kwargs)
TypeError: __init__() missing 1 required positional argument: 'const'

@hktonylee
Copy link

hktonylee commented Jul 14, 2017

Please check out my gist for a working manage.py in gunicorn==19.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment