def norecurse(f):

    def func(*args, **kwargs):
        if len([l[2] for l in traceback.extract_stack() if l[2] == f.__name__]
            ) > 0:
            raise Exception('Recursed')
return f(*args, **kwargs)
return func

@norecurse
def foo(depth=0):
    print(depth)
foo(depth + 1)
foo()
Can a Python method check if it has been called from within itself?