[Python-ideas] Dynamic code NOPing

Victor Stinner victor.stinner at gmail.com
Mon Dec 31 03:00:08 CET 2012


If you mark constant.DEBUG as constant and compile your project with
astoptimizer, enable_debug has no effect (if it was compiled with
DEBUG=False).

So only use it if DEBUG will not be changed at runtime. It cannot be used
if your users might run your applucation in debug mode.

To compare it to the C language, DEBUG would be a #define and astoptimizer
can be see as a preprocessor.

Victor
Le 30 déc. 2012 11:59, "Stefan Behnel" <stefan_ml at behnel.de> a écrit :

> Victor Stinner, 30.12.2012 11:42:
> > My astoptimizer provides tools to really *remove* debug at compilation,
> so
> > the overhead of the debug code is just null.
> >
> > You can for example declare your variable project.config.DEBUG as
> constant
> > with the value 0, where project.config is a module. So the if statement
> in
> > "from project.config import DEBUG ... if DEBUG: ..." will be removed.
>
> How would you know at compile time that it can be removed? How do you
> handle the example below?
>
> Stefan
>
>
> ## constants.py
>
> DEBUG = False
>
>
> ## enable_debug.py
>
> import constants
> constants.DEBUG = True
>
>
> ## test.py
>
> import enable_debug
> from constants import DEBUG
>
> if DEBUG:
>     print("DEBUGGING !")
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121231/cfee0f7f/attachment.html>


More information about the Python-ideas mailing list