Let\'s say I have a Python function f and fhelp. fhelp is designed to call itself recursively. f should not be called rec
You could use a flag set by a decorator:
def norecurse(func):
func.called = False
def f(*args, **kwargs):
if func.called:
print "Recursion!"
# func.called = False # if you are going to continue execution
raise Exception
func.called = True
result = func(*args, **kwargs)
func.called = False
return result
return f
Then you can do
@norecurse
def f(some, arg, s):
do_stuff()
and if f gets called again while it's running, called will be True and it will raise an exeption.