import sys
def a():
print 'aaa'
def profiler(frame, event, arg):
print event, frame.f_code.co_name, frame.f_lineno, "->", arg
# profiler is activated on the next call, return, or exception
sys.setprofile(profiler)
a()
call a 5 -> None#what is it
aaa
return a 6 -> None#what is it
return <module> 12 -> None#what is it
why print this.
The
profilerfunction gets called at each profiling event because you calledsys.setprofileon it.Each time it’s called, it prints a line, because you put an unconditional
printstatement as its body. Why you did that, is hard for us to tell you, making your “why” questions really, truly peculiar.Profiling events are just calls and returns, per the docs:
Here’s what I observe (Python 2.5 or 2.6, MacOSX) in a slightly simpler, sharper case:
Not sure why you don’t see the
c_callandc_returncases as you should — maybe there is no implicitutf-8conversion for printing in your specific platform (what OS? what level of Python? what IDE if any).