Hooking any/all 'calls'

fumanchu fumanchu at amor.org
Thu Dec 28 01:56:49 EST 2006


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