4 ms·
Wow, you just gave me an idea to make retry code with a loop: for _ in repeat_until_success(timeout=10, backoff=0.1): if success(...):
by bvrmn 4y ago
Wow, you just gave me an idea to make retry code with a loop:
for _ in repeat_until_success(timeout=10, backoff=0.1):
if success(...):
break
- Too 4y agoThat’s not taking exceptions into consideration. There is actually a way to do it with loops. for attempt in retry(timeout=10, ..) with attempt: do_stuff() Assuming you have a clever implementation of the retry function. IIRC tenacity has one that works like this.
- bvrmn 4y agoIt's better to make exception handling explicit. It has the same semantic complexity comparing to passing possible good exception types into retry or attempt. Inline loop logic to decide if iteration is successful can be tricky.