Gunicorn: How do I pass an arg to the application that gunicorn runs?

Created on 9 Dec 2010  路  4Comments  路  Source: benoitc/gunicorn

Right now, I start my web app like this:

$ gunicorn webapp:application

I want to feed some parameters to the application function inside my webapp.py. In particular, I want to use a config file to adjust how my webapp works.

I read the docs for how to configure gunicorn with a config file, but I don't want that.

I tried this and got an error:

$ gunicorn webapp:application dev.cfg

As far as I can tell, gunicorn tried to find a callable named named "application dev.cfg".

Any ideas?

Most helpful comment

In your application module you can do something like this:

def load_app(cfg_file):
    cfg = load_app_config(cfg_file)
    return my_app(cfg)

And then you start your app like such:

$ gunicorn 'webapp:load_app("/path/to/my_config.ini")'

All 4 comments

In your application module you can do something like this:

def load_app(cfg_file):
    cfg = load_app_config(cfg_file)
    return my_app(cfg)

And then you start your app like such:

$ gunicorn 'webapp:load_app("/path/to/my_config.ini")'

answered.

@benoitc it's been several years, can you tell me if this answer is still correct? I've not been able to get this approach to work for me.

@pellunutty I don't think the answer is correct now. You can subclass one of the application classes (e.g. BaseApplication) and parse relevant information in load_config method. See http://docs.gunicorn.org/en/stable/custom.html for an example.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

obi1kenobi picture obi1kenobi  路  78Comments

kozmaz87 picture kozmaz87  路  34Comments

erjiang picture erjiang  路  34Comments

Jwpe picture Jwpe  路  45Comments

jezdez picture jezdez  路  90Comments