Skip to content

Instantly share code, notes, and snippets.

@najeira
Created November 5, 2011 14:55
Show Gist options
  • Save najeira/1341622 to your computer and use it in GitHub Desktop.
Save najeira/1341622 to your computer and use it in GitHub Desktop.
QueryIterator for async - Google App Engine / Python
class QueryIterator(object):
def __init__(self, query, limit=None):
self.limit = limit
self.count = 0
if limit:
config = datastore_query.QueryOptions(limit=limit, prefetch_size=limit)
else:
config = None
self.iterator = query.run(config=config)
def __iter__(self):
return self
def next(self):
if self.limit and self.limit <= self.count:
raise StopIteration()
self.count += 1
return self.iterator.next()
def get_result(self):
return [e for e in self]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment