views:

107

answers:

1

Is there a way to programmatically trace the execution of all python functions/methods? I would like to see what arguments each of them was called with. I really mean all, I'm not interested in a trace decorator.

In Ruby, I could alias the method I wanted and add the extra behaviour there.

+3  A: 

Have a look at the trace module.

You can also use it via the command line:

python -m trace --help
jls
how does this work in python? I know in ruby what I have to do to make it work, I would like to know what python does for me.
Geo
Sorry I'm not quite sure what you're asking. Are you interested to know how the tracing mechanism works or how to use the trace module?
jls
I'm interested in how tracing in python works. Just the general idea of what python does behind the scene.
Geo
In a sentence, the trace modules adds handlers via sys.settrace (which sets the system's trace function). The docs give a pretty overview of what's involved with this: http://docs.python.org/library/sys.html#sys.settrace
jls
Thanks! I'll look into the mechanism.
Geo