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 <bemmu....@gmail.com> 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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to