python -m trace -t main.py
Тестовая программа:
main.py
from a import g
def f(i):
g(i)
for i in range(3):
f(i)
a.py
def g(i):
print i
Выход:
--- modulename: main, funcname: <module>
main.py(1): from a import g
--- modulename: a, funcname: <module>
a.py(1): def g(i):
main.py(2): def f(i):
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
0
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
1
main.py(4): for i in range(3):
main.py(5): f(i)
--- modulename: main, funcname: f
main.py(3): g(i)
--- modulename: a, funcname: g
a.py(2): print i
2
main.py(4): for i in range(3):
--- modulename: trace, funcname: _unsettrace
trace.py(80): sys.settrace(None)
Протестировано на Ubuntu 16.10, Python 2.7.12.