Git Product home page Git Product logo

Comments (5)

mayank-kgp avatar mayank-kgp commented on May 22, 2024 1

With the except block, code is not retrying at all because when exception is being raise first time, it is being handled by except block. So, backoff library is not considering the fact that function is throwing any exception in the first place.

from backoff.

pypae avatar pypae commented on May 22, 2024

The documentation states:

When a give up event occurs, the exception in question is reraised and so code calling an on_exception-decorated function may still need to do exception handling.

So you should be able to do:

@backoff.on_exception(backoff.expo,
                      requests.exceptions.RequestException,
                      on_backoff=backoff_hdlr)
def get_url(url):
    return requests.get(url)

def get_url_or_default(url, default=None):
    try:
        return get_url(url)
    except requests.exceptions.RequestException:
        return default

Note: Code is an untested draft.

from backoff.

bgreen-litl avatar bgreen-litl commented on May 22, 2024

@PatDue is correct. With on_exception, once the retrying is done, the exception that caused retry is raised and you can handle that exception and do whatever you like.

@sagarr I should note though, that in your code snippet you don't specify any of the keyword args that would cause backoff to give up at all. You need to use max_tries or max_time or giveup to trigger backoff.on_exception to stop trying.

from backoff.

bgreen-litl avatar bgreen-litl commented on May 22, 2024

@mayank-kgp I don't know what you mean. Can you provide example code if you're reporting a bug?

from backoff.

AanandhiVB avatar AanandhiVB commented on May 22, 2024

Hi,

I might be missing something here, I tried looking into docs and all issues, but didn't get anything..

Here what I want, I want to return default value once all the retrying is done, like

def backoff_hdlr(details):
   return None # tried getting value from URL, now just return None

@backoff.on_exception(backoff.expo,
                      requests.exceptions.RequestException,
                      on_backoff=backoff_hdlr)
def get_url(url):
    return requests.get(url)

Hi, I am facing the same problem as well. Were you able to solve this issue?
Is there a way for backoff decorator to return the value of backoff_hdlr as value of get_url function?

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.