2

The python documentation defines a global constant named __debug__ :

__debug__

This constant is true if Python was not started with an -O option. See also the assert statement.

I'm using some python library under my production Django site (Apache/WSGI based) which checks this constant before executing debug-only code.To my surprise, that code is being executed in production.

As the Django site was not started via the python command line interperter, I was wondering what controls this __deubg__ constant?

Community
  • 1
  • 1
Boaz
  • 25,331
  • 21
  • 69
  • 77

3 Answers3

1

For the sake of all who follow, this is the wsgi directive you are looking for: WSGIPythonOptimize

The documentation states:

The default is '0' which means no optimisations are applied.

So in the default case __debug__ would be True.

turtlemonvh
  • 9,149
  • 6
  • 47
  • 53
1

Looks like you can use the PYTHONOPTIMIZE environment variable. You may need to set it from your apache configuration... Not too sure I haven't used the standard WSGI setup in a long time.

meshantz
  • 1,566
  • 10
  • 17
  • Thanks, this helped me solve my problem too. All I had to do was "export PYTHONOPTIMIZE=1" before running "manage.py runserver" – tom Oct 01 '14 at 14:52
0

Is settings.DEBUG set to False?

girasquid
  • 15,121
  • 2
  • 48
  • 58
lprsd
  • 84,407
  • 47
  • 135
  • 168