Hooking any/all 'calls'

Kevin Little kevin_little at comkast.net.k2c
Thu Dec 28 15:53:09 EST 2006


Thanks, Robert! That was exactly what I was looking for.
     -k

"fumanchu" <fumanchu at amor.org> wrote:
>Kevin Little wrote:
>> In Python 2.4 or 2.5, what is the easiest way to hook any and all
>> callables such that designated code is executed at the very start and
>> end of each call? (Yes, I'm trying to come up with a little debugging
>> tool!:) Is there a single metaclass who's "__call__" method can be
>> wrapped to do this?
>
>You probably want sys.settrace, which is specifically designed for
>creating debuggers, and is the basis for pdb, the debugger in the
>standard library. See
>http://docs.python.org/lib/module-sys.html#l2h-5159
>
>Feel free also to look through my own debugging aid (for clues on how
>to implement your own, or just to use for your needs):
>http://projects.amor.org/misc/wiki/PyConquer
>
>
>Robert Brewer
>System Architect
>Amor Ministries
>fumanchu at amor.org



More information about the Python-list mailing list