If I create a python decorator function like this
def retry_until_true(tries, delay=60):
"""
Decorator to rety a function or method until it returns True.
"""
def deco_retry(f):
def f_retry(*args, **kwargs):
mtries = tries
rv = f(*args, **kwargs)
while mtries > 0:
if rv is True:
return True
mtries -= 1
time.sleep(delay)
rv = f(*args, **kwargs)
return False
return f_retry
return deco_retry
I can use it like this
@retry_until_true(20, delay=30)
def check_something_function(x, y):
...
return True
But is there a way to pass different values for 'tries' and 'delay' to the decorator at runtime, so that 20 and 30 are variables?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…