开发者

How to access Gunicorn's configuration params from application code?

开发者 https://www.devze.com 2023-01-26 09:13 出处:网络
I have a Werkzeug application served on gunicorn. The script directory layout looks like this: prj/ __init__.py

I have a Werkzeug application served on gunicorn. The script directory layout looks like this:

prj/
    __init__.py
    application.py   :which has a WSGI application object "wsgi_app".
    settings_app.py  :settings for werkzeug applicaiton code.

Then, I usually use the following command-line to start the Werkzeug application on gunicorn.

$ gunicorn --worker-class=gevent --bind=0.0.0.0:80 --workers=5 --daemon [--debug] prj.application:wsgi_app

In case of "--debug", gunicorn turns on debugging. Because the "debug" variable of gunicorn affects only gunicorn itself behavior, I also put "DEBUG" variable in "settings_app.py" to change the application's behavior(logging level, template directory, and so on). I feel that is not DRY. Moreover, command-line "debug" option can not override the later "DEBUG" variable.

If gunicorn's configuration variables can be referred in the application code, I can ommit such duplicate copies of variables.

How to access gunicorn's 开发者_Python百科configuration variables from application code?

Thanks.


Currently there's no direct way to be able to import Gunicorn config parameters into your application code.

What you could do is use one of the various config hooks to automatically set the debug variable in your application code.


You can use use optparse before Gunicorn parses args.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号