You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2025. It is now read-only.
>>> x = backoff.on_exception(backoff.fibo, Exception, max_tries=4, jitter=None)(t)
>>> x()
Backing off t() 1.0s (Exception: a)
Backing off t() 1.0s (Exception: a)
Backing off t() 2.0s (Exception: a)
Giving up t() after 4 tries (Exception: a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vagrant/backoff/backoff.py", line 302, in retry
ret = target(*args, **kwargs)
File "<stdin>", line 2, in t
Exception: a
>>> x = backoff.on_exception(backoff.factor(backoff.fibo, 0.1), Exception, max_tries=4, jitter=None)(t)
>>> x()
Backing off t() 0.1s (Exception: a)
Backing off t() 0.1s (Exception: a)
Backing off t() 0.2s (Exception: a)
Giving up t() after 4 tries (Exception: a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vagrant/backoff/backoff.py", line 302, in retry
ret = target(*args, **kwargs)
File "<stdin>", line 2, in t
Exception: a
As it turns out, we currently support a factor keyword argument on the backoff.expo wait generator. Your PR concerns making it available to the backoff.fibo wait generator as well. This seems like a good idea.
The way backoff handles parameterization of the wait generators is that any extra keyword arguments supplied in the decorator function declaration are passed to the wait generator at invocation time. For consistency with backoff.expo's support of factor, as well as in the interest of keeping the API surface as small as possible, I think this feature could be most cleanly implemented as an additional keyword arg to backoff.fibo.
Untested, but I think the implementation would be:
def fibo(max_value=None, factor=1):
a = 1
b = 1
while True:
if max_value is None or a * factor < max_value:
yield a * factor
a, b = b, a + b
else:
yield max_value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
3 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@bgreen-litl pls review
factordecorator to control sleep time unit.