GithubHelp home page GithubHelp logo

Comments (5)

bgreen-litl avatar bgreen-litl commented on August 23, 2024 1

Woah, I just looked at my own at example more carefully and it's weirder than that. The KeyError wait generator is getting reset each time. I think combining decorators doesn't work as neatly as was supposed. :/

from backoff.

bgreen-litl avatar bgreen-litl commented on August 23, 2024

You are seeing the effect of the default jitter behavior backoff.full_jitter. See documentation here. You can read more here. If you don't want that behavior you can use a different jitter strategy, or pass jitter=None for no jitter at all.

from backoff.

martinvol avatar martinvol commented on August 23, 2024

Thanks a lot for your answer! Should I submit a PR to update this section of the docs?

I find this behavior is not intuitive (at least for me).

from backoff.

bgreen-litl avatar bgreen-litl commented on August 23, 2024

So I think your original report was correct, and I was confused because full_jitter was on. Full jitter can cause the value to go down from one retry to the next, but the behavior your were citing is real independent of jitter.

Here's an example with jitter disabled:

In [7]: @backoff.on_exception(backoff.expo, ValueError, jitter=None)
...: @backoff.on_exception(backoff.expo, KeyError, jitter=None)
...: def foo(calls=[ValueError(), KeyError(), ValueError(), KeyError(), Value
...: Error(), KeyError(), ValueError()]):
...: raise calls.pop()
...:

In [8]: foo()
Backing off foo(...) for 1.0s (ValueError)
Backing off foo(...) for 1.0s (KeyError)
Backing off foo(...) for 2.0s (ValueError)
Backing off foo(...) for 1.0s (KeyError)
Backing off foo(...) for 4.0s (ValueError)
Backing off foo(...) for 1.0s (KeyError)
Backing off foo(...) for 8.0s (ValueError)

You can see that each exception type gets its own wait sequence. This is because each decorator defines and instantiates its own wait generator. I think this is probably unavoidable, and probably(?) desirable. Consider if you wanted to do exponential backoff for one type of exception and constant backoff for another.

I think you're right that at the least it could be documented better. At of curiosity, do you have a real world case where you wanted to define different behavior for different exceptions?

from backoff.

martinvol avatar martinvol commented on August 23, 2024

I think you're right that at the least it could be documented better. At of curiosity, do you have a real world case where you wanted to define different behavior for different exceptions?

Yes, just hitting an API and if I get an exception related with bad formatting I don't want to retry, but if I hit any other exception I want to back off exponentially.

from backoff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.