Whats wrong with: >>> sysconfig.get_config_var('Py_DEBUG') 0
Nir On Fri, Oct 2, 2015 at 10:18 AM, Victor Stinner <victor.stin...@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 >
_______________________________________________ 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/archive%40mail-archive.com