[Zope-dev] MonkeyPatching in the Core (was: Zope 2.6 planning)

Matthew T. Kromer matt@zope.com
Mon, 04 Mar 2002 17:35:50 -0500


With respect to the overhead of inserting things into modules in the 
source code, Fred Drake (I think!) pointed out to me that constructs in 
the form

    if __debug__: ...

are automatically removed by the parser when Python is run with the -O flag.

Note that I am *not* sure how Zope performs when run with Python -O. 
 However, assuming it does run OK, then it makes sense to put all sorts 
of conditional things into code which are disabled for performance when 
-O is passed on the command line to Python.

Also note that I guarantee Zope will not run with Python -OO, as this 
removes doc strings, which the Publisher relies upon.

At the time, I was pushing more for a slightly more complex form of run 
time diagnostic control without the overhead of continuous symbol 
lookup, e.g. ifcondition(bitmask): such that either all the bits in the 
bitmask were "enabled" in the current debugging context, or at least 
some of them were.

Then again, I effectively want exits in Python's ceval.c at various 
locations to be able to do "magic" without the burden of more 
interpretation.  For instance, there are actually some clever things you 
can do with the new C level profiler, but 'stealing' the profiler to do 
other magic is not really the right approach.

-- 
Matt Kromer
Zope Corporation  http://www.zope.com/