Expansion of the __debug__ and pass concepts

c_ullman at yahoo.com c_ullman at yahoo.com
Tue Oct 31 14:38:06 EST 2000


Hi,

My company is working on a large of multi-threaded, multi-client, multi-
server application.  The majority of it is based in python.

Here is the problem.  We came up with a generalized debugging
printf that could be assigned masks for severity reporting, etc.
It looks something like this :
DBG(DBG.DM_DEFAULT, "The value for x is : %d", x)

We have encouraged our developers to use the mechanism often.  So
we have probably one of these statements for every 5 or 6 lines of code.

So, even if we tell our debugging mechanism to silence all debug
information this still has a tremendous impact on performance. The
ideal solution would be a way for us to essentially remove these
statements when -O was specified for production use.

We explored a couple of ways of doing this, I looked into bytecodehacks,
but that seemed like we would have to wrapper every function we were
doing this for.

What we ended up doing was making our own version of python that
replaces all DBG's with pass statements at parse time if the -O
is specified.  This speeds up our application considerably.
However, we don't like have a  special version of python, and this
is not very general purpose.

I think there a couple of ways we could add this functionality
in a generic way to python.

1) Create an IFDEF like, preprocessor system for python.

2) Improve the byte-code optimizer so if I did this:

if __debug__:
    def DBG(*args):
       pass

The optimizer would figure out that DBG never did anything and
optimize it away.

3) Expand the concept of pass so that it will now take arguments.
For example, all the following would now be legal python:
pass
pass(5)
pass(5, x=6)
etc...

Then we could do this in python
if __debug__:
    DBG = pass


The third option is our current favorite.  I think that this
wouldn't be overly difficult to implement, would not break any
existing python scripts, and remains true to the way python
currently works.

Any comments, suggestions?  Am I missing an easy way to do this
that exists today?  Should I write up a PEP?

TIA,

Cayce


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list