From: John Reid on
Can I check in the interpreter if I am running a debug version of
python? I don't mean if __debug__ is set, I want to know if python was
compiled in debug mode.

Thanks,
John.

From: Christian Heimes on
> Can I check in the interpreter if I am running a debug version of
> python? I don't mean if __debug__ is set, I want to know if python was
> compiled in debug mode.

Python has multiple flavors of debug builds. hasattr(sys,
"gettotalrefcount") is only available if Py_REF_DEBUG is enabled. This
should be sufficient to detect the most used debug variant.

Christian


From: Christian Heimes on
> Starting with Python 2.7 and 3.2 you can do this:
>
>>>> sysconfig.get_config_var("Py_DEBUG")
> 1
>
> (returns None if the var doesn't exist)

IIRC sysconfig.get_config_var() still depends on parsing the pyconfig.h
file. This won't work on Windows because we are using project and config
settings of VisualStudio.