Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24636

Re: retry many times decorator

Date 2012-06-28 22:11 +0100
From Andrea Crotti <andrea.crotti.0@gmail.com>
Subject Re: retry many times decorator
References <CAF_E5JYVNQmf7yptnuarqV8=aVPaix5xQg-q9bFe3Cg8wwPNYg@mail.gmail.com> <4FEC8278.7020806@mrabarnett.plus.com> <mailman.1612.1340900799.4697.python-list@python.org> <4fec97d9$0$29978$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.1621.1340917948.4697.python-list@python.org> (permalink)

Show all headers | View raw


On 06/28/2012 06:43 PM, Steven D'Aprano wrote:
> On Thu, 28 Jun 2012 17:26:36 +0100, andrea crotti wrote:
>
>
> I disagree. If you make a coding error in your function, why do you think
> it is useful to retry that buggy code over and over again? It's never
> going to get less buggy unless you see the exception and fix the bug.
>
> For any operation that you want to retry, identify the *temporary*
> errors, catch them, and retry the request. *Permanent* errors should
> immediately fail, without retrying. *Unexpected* errors should not be
> caught, since they probably represent a bug in your code.

Ah well maybe I wasn't clear, but I'm not going to retry random things, 
I will only decorate
the functions that I know for sure that could go wrong for temporary 
network problems.

For example they told me that sometimes mysql just doesn't respond in 
time for some reasons,
but there's nothing permanently wrong, so retrying is the best option..

It would be good of course, however, to catch the exceptions that are 
known to be permanent problems
in the function at least, and leave the retry as last resource..

Thanks for the idea of the exponential backoff, which is also a better 
name than timeout for the variable..

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: retry many times decorator andrea crotti <andrea.crotti.0@gmail.com> - 2012-06-28 17:26 +0100
  Re: retry many times decorator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-06-28 17:43 +0000
    Re: retry many times decorator Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-06-28 22:11 +0100
    Re: retry many times decorator andrea crotti <andrea.crotti.0@gmail.com> - 2012-06-29 09:53 +0100
      Re: retry many times decorator Justin Barber <barber.justin@gmail.com> - 2012-06-29 05:45 -0700
      Re: retry many times decorator Justin Barber <barber.justin@gmail.com> - 2012-06-29 05:45 -0700

csiph-web