[Python-ideas] Runtime assertion with no overhead when not active

Serhiy Storchaka storchaka at gmail.com
Tue May 8 12:08:59 EDT 2018


08.05.18 18:34, Steven D'Aprano пише:
> I don't even know which builds of Python I'm running. My *guess* is that
> the OS-provided Python is probably a non-debug build, and the ones I've
> compiled from source will be whatever the default build settings are,
> but I don't know what that is or how to find out.

There are different means of "debug build".

It may mean that binaries are build with enabling runtime checks in C 
code. When you build from sources you will get a non-debug build by 
default. You need to pass a special option --with-pydebug to ./configure 
for getting a debug build. The OS-provided Python is a non-debug build too.

It may means that the "assert" statement in Python code is not a no-op 
and the building __debug__ constant is True. Python is ran in debug mode 
by default. You have to pass the -O option to the python command for 
running Python in non-debug mode. ISTM the OP uses the term "debug 
build" in this meaning.

Finally, a special "development mode" mode was introduced in 3.7. It is 
enabled by the command line option -X dev. It switches on several 
expensive runtime checks in C code (if they are not switched off by 
compiling binaries in "release build" in the first meaning).

https://docs.python.org/3.8/whatsnew/3.7.html#new-development-mode-x-dev

All these things are virtually orthogonal and can be combined arbitrary.



More information about the Python-ideas mailing list