Quick tracing

Mon 28 April 2014

Here's a quick way to see what code is actually run when calling some library.

Just create a file shell.py with this in it:

import code
con = code.InteractiveConsole()
con.interact()

Note

code, codeop, __future__ modules are ignored so you don't see the trace for the code handling the REPL.

Then run:

python -mtrace --ignore-module=code,codeop,__future__ --trace shell.py

Ta-da!

>>> os.path.isfile('/')
 --- modulename: utf_8, funcname: decode
utf_8.py(16):     return codecs.utf_8_decode(input, errors, True)
 --- modulename: genericpath, funcname: isfile
genericpath.py(28):     try:
genericpath.py(29):         st = os.stat(path)
genericpath.py(32):     return stat.S_ISREG(st.st_mode)
 --- modulename: stat, funcname: S_ISREG
stat.py(50):     return S_IFMT(mode) == S_IFREG
 --- modulename: stat, funcname: S_IFMT
stat.py(25):     return mode & 0170000
False

This entry was tagged as python debugging

blog comments powered by Disqus