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

leonardbinet picture leonardbinet  ·  4Comments

zenglingyu picture zenglingyu  ·  4Comments

thomasjungblut picture thomasjungblut  ·  3Comments

benoitc picture benoitc  ·  4Comments

mrwillis picture mrwillis  ·  4Comments