Got it, thanks.
On Aug 25, 11:50 am, Alkis Evlogimenos ('Αλκης Ευλογημένος)
<[email protected]> wrote:
> @retry_on_timeout(retries=10, secs=0.2)
> def some_idempotent_function(): # do stuff
>
> If you do not give retries or secs it defaults to 3 retries with 1 sec
> starting delay. The delay is exponential, it doubles after each retry.
>
> 2009/8/25 Devel63 <[email protected]>
>
>
>
>
>
> > Can you give an example as to how this is used? I understand the
> > purpose, I'm just a little hazy on the calling syntax.
>
> > On Aug 24, 5:25 am, Alkis Evlogimenos ('Αλκης Ευλογημένος)
> > <[email protected]> wrote:
> > > You can make it into a decorator which will make it easier for your
> > > functions to code. I use this:
> > > def retry_on_timeout(retries=3, secs=1):
> > > """A decorator to retry a given function performing db operations."""
> > > def _decorator(func):
> > > def _wrapper(*args, **kwds):
> > > tries = 0
> > > while True:
> > > try:
> > > tries += 1
> > > return func(*args, **kwds)
> > > except db.Timeout, e:
> > > logging.debug(e)
> > > if tries > retries:
> > > raise e
> > > else:
> > > wait_secs = secs * tries ** 2
> > > logging.warning("Retrying function %r in %d secs" % (func,
> > > wait_secs))
> > > time.sleep(wait_secs)
> > > return _wrapper
> > > return _decorator
>
> > > On Mon, Aug 24, 2009 at 1:53 PM, Bemmu <[email protected]> wrote:
>
> > > > I decided to finally do something about the Timeout exceptions
> > > > littering my log.
>
> > > > I read somewhere on this forum that I am supposed to code around data
> > > > store accesses to try things out several times in case of timeouts. Is
> > > > this still necessary? Why won't the methods just do that internally?
>
> > > > This is my first attempt to handle a timeout situation, is there any
> > > > nicer way to code this?
>
> > > > retries = 3
> > > > retry = True
> > > > while retry:
> > > > try:
> > > > retry = False
> > > > recipient.put()
> > > > except:
> > > > retries -= 1
> > > > if retries > 0:
> > > > retry = True
> > > > logging.info("recipient.put() failed,
> > > > retrying")
> > > > else:
> > > > logging.error("failed even after trying
> > > > recipient.put() three
> > > > times")
>
> > > --
>
> > > Alkis
>
> --
>
> Alkis
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---