tenacity
tenacity copied to clipboard
when Changing Arguments at Run Time with `retry_with`, `retry.statistics` return `{}`
venv
- Window 10
- Python 3.9.7
- tenacity 8.0.1
Here the reproduce code from Changing Arguments at Run Time:
@retry(stop=stop_after_attempt(3))
def raise_my_exception():
print("raise_my_exception")
raise Exception("Fail")
try:
raise_my_exception.retry_with(stop=stop_after_attempt(4))()
except Exception:
pass
print(raise_my_exception.retry.statistics)
Here what I got:
raise_my_exception
raise_my_exception
raise_my_exception
raise_my_exception
{}
Here I dig into to code what I got:
https://github.com/jd/tenacity/blob/ff4843121c4763759d3d9806d18aaf642651a650/tenacity/init.py#L264-L275
when call retry_with()
, it will return a new instance of BaseRetrying
, and not copy of old one retry.statistics
I made this clear:
raise_my_exception.retry_with(stop=stop_after_attempt(4))
will return a new instance, the original raise_my_exception does not run,
so it should be
try:
new_instance = raise_my_exception.retry_with(stop=stop_after_attempt(4))
new_instance()
except Exception:
pass
print(new_instance.retry.statistics)
This is docs mistakes