# @type code org.darkhelm.showsort.server.Codedef tracer(code):"""Simple decorator function that handles identification of recursion and thename of the current function to ShowSort. It must have the code parameterbe set to the Java Code object that will be executing the function."""import sys
def wrapAll(func):def wrappedFunc(*args, ** kwargs):top = sys._getframe(1)
current = top
while current.f_back:current = current.f_backif top.f_code == current.f_code:code.recurse() # Tell ShowSort that a recursion happened.break
code.pyFuncName = func.__name__ # Tell ShowSort the name of the function.
return func(*args, ** kwargs)
wrappedFunc.__doc__ = func.__doc__
return wrappedFunc
return wrapAll
Cliff,You could use this recipe as a basis for something like this. The recipe is not at all general purpose (there was some controversy about its claims), but it does illustrate how you can introspect function frames without having to introduce another stack to record what's going on - that does work in a general fashion:If you're interested in doing this sort of thing, I tend to favor the inspect module.- Jim