tenacity
tenacity copied to clipboard
update argument for method in Retry
from tenacity import retry, retry_if_exception_type, stop_after_attempt
@retry(retry=retry_if_exception_type(ValueError), stop=stop_after_attempt(3))
def aa(value):
try:
print(value)
raise ValueError
except ValueError:
value = value +1 # want to update the value here for next iteration.
raise
aa(5) # call method
Above is minimal reproduceable example. Here I want to update the method argument in each retry i.e. when the input is passed as 5 and it threw exception, for the next iteration it should get changed to 6 and again by 1 for next subsequent retry which is not happening.
Is there any way to achieve this, also I cant put this in old fashion of retrying (to have counter of running times and exit when exhausted the required limit of retrying)
Looks like you want to use the for
loop invocation of tenacity.
Have a look at this example: https://tenacity.readthedocs.io/en/latest/#retrying-code-block