This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2015-09-28.13:14:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1443446100.69.0.307482207939.issue25256@psf.upfronthosting.co.za>
In-reply-to
Content
Attached patch adds the sys.is_debug_build() public function and replaces hasattr(sys, xxx) tests to check for debug mode with sys.is_debug_build().

+.. function:: is_debug_build()
+
+   Return :const:`True` if the Python executable was compiled in debug mode,
+   return :const:`False` if it was compiled in release mode.
+
+   The debug mode is enabled with ``#define Py_DEBUG``, or with
+   ``./configure --with-pydebug``.
+
+   .. versionadded:: 3.6

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.

For example, 3 different checks are proposed on StackOverflow and only one looks portable:

http://stackoverflow.com/questions/646518/python-how-to-detect-debug-interpreter

I don't think that we need to mark the function as an implementation detail or specific to CPython. Other implementations of Python would probably benefit from such flag. If they don't care, they can simply return False.

Alternative: Add a new sys.implementation.debug_build flag.

Note: I chose the "is_debug_build" name using the existing sysconfig.is_python_build(). There is a sys.flags.debug flag, so "is_debug()" can be confusing. I prefer to attach the "build" suffix.
History
Date User Action Args
2015-09-28 13:15:01vstinnersetrecipients: + vstinner
2015-09-28 13:15:00vstinnersetmessageid: <1443446100.69.0.307482207939.issue25256@psf.upfronthosting.co.za>
2015-09-28 13:15:00vstinnerlinkissue25256 messages
2015-09-28 13:15:00vstinnercreate