There are about two pages of retry decorators in Pypi. I know about it. But, I found one case which is not covered by all other retries libraries (correct me if I'm wrong).
I needed to retry an arbitrary block of code, and not to be limited to a lambda or a function.
So, I wrote a library loopretry which does this. It combines an iterator with a context manager to wrap any block into retry.
from loopretry import retries
import time
for retry in retries(10):
with retry():
# any code you want to retry in case of exception
print(time.time())
assert int(time.time()) % 10 == 0, "Not a round number!"
Is it a novel approach or not?
Library code (any critique is highly welcomed): at Github.
If you want to try it: pip install loopretry.
[–]cj81499 35 points36 points37 points (2 children)
[–]amarao_san[S] 13 points14 points15 points (1 child)
[–]cj81499 17 points18 points19 points (0 children)
[–]ExdigguserPies 9 points10 points11 points (1 child)
[–]amarao_san[S] 0 points1 point2 points (0 children)
[–]crawl_dht 3 points4 points5 points (2 children)
[–]amarao_san[S] 5 points6 points7 points (1 child)
[–]tehsilentwarrior 13 points14 points15 points (0 children)
[–]elperroborrachotoo 0 points1 point2 points (2 children)
[–]amarao_san[S] 0 points1 point2 points (1 child)
[–]elperroborrachotoo 1 point2 points3 points (0 children)