By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,171 Members | 809 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,171 IT Pros & Developers. It's quick & easy.

Hooking any/all 'calls'

P: n/a
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

Dec 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
At Wednesday 27/12/2006 23:07, 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?
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

Dec 28 '06 #2

P: n/a
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
fu******@amor.org

Dec 28 '06 #3

P: n/a
Thanks, Robert! That was exactly what I was looking for.
-k

"fumanchu" <fu******@amor.orgwrote:
>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
fu******@amor.org
Dec 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.