(original) (raw)
Whats wrong with:
>>> sysconfig.get\_config\_var('Py\_DEBUG')
0
Nir
On Fri, Oct 2, 2015 at 10:18 AM, Victor Stinner <victor.stinner@gmail.com> wrote:
Hi,
I created the issue "Add sys.debug\_build public variable to check if
Python was compiled in debug mode": http://bugs.python.org/issue25256
I would like to add an obvious way to check if Python was compiled in
debug mode, instead of having hacks/tips to check it. On the Internet,
I found various recipes to check if Python is compiled is debug mode.
Sadly, some of them are not portable. For example, 3 different checks
are proposed on StackOverflow but 2 of them are specific to Windows:
http://stackoverflow.com/questions/646518/python-how-to-detect-debug-interpreter
Even if the exact impact of a debug build depends on the Python
implementation and the Python version, we can use it to have the same
behaviour on all Python implementations. For example, the warnings
module shows warnings by default if Python is compiled in debug mode:
Extract of my patch:
\- if hasattr(sys, 'gettotalrefcount'):
\+ if sys.debug\_build:
resource\_action = "always"
else:
resource\_action = "ignore"
Alternative: Add a new sys.implementation.debug\_build flag. Problem:
extending sys.implementation requires a new PEP, and I don't think
that debug\_build fits into this object.
Berker Peksag likes the idea.
Serhiy Storchaka dislike the new flag: "I don't like this. The sys
module is one of most used module, but it has too many members, and
adding yet one makes the situation worse." (sys has 81 symbols)
"Checking for debug mode is not often needed, and mainly in tests.
Current way \`\`hasattr(sys, 'gettotalrefcount')\`\` works good. You also
can check \`\`'d' in sys.abiflags\`\` if it looks cleaner to you. Or add a
member to test.support."
The name "debug\_build" comes from the existing
sysconfig.is\_python\_build() function. There is a sys.flags.debug flag,
so "sys.debug" can be confusing. I prefer to attach the "build"
suffix.
First I proposed a function sys.is\_debug\_build(), but a flag is
simpler than a function. There is not need to compute a version it's
known at build time.
What do you think? Should we add sys.debug\_build?
Victor
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/nirsof%40gmail.com