如果我像这样创建一个 python 装饰器函数
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
我可以这样使用
@retry_until_true(20, delay=30)
def check_something_function(x, y):
...
return True
但是有没有办法在运行时将“尝试”和“延迟”的不同值传递给装饰器,以便 20 和 30 是变量?