Hooking any/all 'calls'

K

Kevin Little

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?

TIA,
-k
 
G

Gabriel Genellina

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?

See Stain Soiland's site http://soiland.no/software/decorator for his
logging decorator and logging metaclass.


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 
F

fumanchu

Kevin said:
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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top