By optimized mode I mean no asserts, possibly no doc strings, .pyo
rather then .pyc
.
In short I have a django project runnning through gunicorn(v18.0) in the standard style (gunicorn 'module.wsgi:application'
)
I have been unable to find a reference in the docs or elsewhere online.
You can set the PYTHONOPTIMIZE
environment variable if you really understand what you are doing.
# e.g.
# same as -O
export PYTHONOPTIMIZE=1
# same as -OO
export PYTHONOPTIMIZE=2
Reference: Python doc: Command line and environment
PYTHONOPTIMIZE
If this is set to a non-empty string it is equivalent to specifying the -O option. If set to an integer, it is equivalent to specifying -O multiple times.
But normally you should never do it !!!
Deestan's answer for another SO question "Best practice for Python Assert" is really great:
Asserts should be used to test conditions that should never happen.
The purpose is to crash early in the case of a corrupt program state.
Usually a django application uses many other libraries. When something critical happens, and those libraries believe that the application should crash immediately, they follow the best practice above and use asserts. You don't want to break that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With