假设我有以下功能:
@retry(stop=stop_after_attempt(3))
def foo():
try:
response = requests.post(...)
response.raise_for_status()
return response
except Exception as e:
raise e
该函数将重试 3 次,如果所有 3 次重试都失败,则会引发异常。
如何在不引发异常的情况下使用坚韧进行 3 次重试?就像是:
@retry(stop=stop_after_attempt(3))
def foo(ignore_errors=False):
try:
response = requests.post(...)
response.raise_for_status()
return response
except Exception as e:
if ignore_errors and function has been retried three times:
pass
raise e