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.
精彩评论