Closed RainrainWu closed 10 months ago
Thanks for the PR and sorry for a very slow response.
The thing is adding extra params to retry feels like a way to nowhere. Also, timeout already accepts callables so one might simply:
@retry(..., timeout=lambda attempt: min(60, 2 ** attempt * random.uniform(0.5, 2)))
def some_func(...):
pass
# Or if need it many times:
def exp_backoff(exp, jitter_amp=1, cap=float("inf")):
return lambda attempt: min(exp ** attempt * random.uniform(1.0 / jitter_amp, jitter_amp), cap)
@retry(..., timeout=exp_backoff(2, jitter_amp=2, cap=60))
def some_func(...):
pass
Which will reach the same purpose easier.
The above exp_backoff()
might be included into funcy on its own of cause. It is a oneliner though.
@Suor Thanks for the reply!
I totally agree that the current implementation is much more flexible, the PR is trying to look for a more straightforward approach to getting started :)
It is ok to be closed if the design does not align with your expectation 😃
Summary
Checklist
Reason
timeout
can also accept a callable object without tracing the source code.