Dealing with db.Timeout on Google App Engine
google-app-engine, python
Solution
Queries will occasionally fail. You can either show an error message to the user, or retry, as you're doing above. If you retry, however, you should use thread.sleep to add increasing amounts of delay (starting at, say, 50ms) on each retry - retries are more likely to succeed if they're not retried as fast as possible.
40 queries per request is a lot, though. You should consider refactoring your code - it must be possible to eliminate most of those!
Problem
I'm testing my application (on Google App Engine live servers) and the way I've written it I have about 40 db.GqlQuery() statements in my code (mostly part of classes). I keep getting db.Timeout very often though. How do I deal with this? I was going to surround all my queries with really brutal code like this: ``` querySucceeded = False while not querySucceeded : try : result = db.GqlQuery( """xxx""" ).get() querySucceeded = True #only get here if above line doesn't raise exc except : querySucceeded = False ``` Is this ok? Do you agree? What's a better way to deal with db.Timeouts? Edit: I now use this for any get queries ``` """ Query gets single result """ def queryGet( gql ) : querySucceeded = False while not querySucceeded : try : result = db.GqlQuery( gql ).get() querySucceeded = True #only get here if above line doesn't raise except : querySucceeded = False return result ``` I have similar functions for fetch and count.