[perhaps of faint interest to python programmers, certainly not to anybody else]
This is immensely useful for debugging, and for getting a feel for the structure of a program. It’s something you could theoretically already do with epydoc and a profiler, but that’s always seemed like a lot of work for little return.
With pycallgraph, it takes a couple of lines:
#…code to be graphed goes here
That’s still a lot of typing, though, when I really only want it for a quick picture of whatever is currently baffling me. pycallgraph have missed an opportunity to rewrite it as a decorator:
(filename = ‘
callwrapper.already_called = True
pycallgraph.start_trace(reset = False)
result = func(*args, **kwargs)
callwrapper.already_called = False
This lets me generate a call-graph of any function, by popping a one-line decorator onto it:
The other advantage here is that I generally only want to generate the graph once, when the function is first called. Hence the use of afunction attribute, already_called, as a flag to short-circuit past the call-graph on subsequent runs.