10

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.

1 Answer 1

13

Have a look at the trace module.

You can also use it via the command line:

python -m trace --help
Sign up to request clarification or add additional context in comments.

6 Comments

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.
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?
I'm interested in how tracing in python works. Just the general idea of what python does behind the scene.
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: docs.python.org/library/sys.html#sys.settrace
Thanks! I'll look into the mechanism.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.