我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用google.appengine.ext.db.Timeout()。
def flush(self): """Force a flush.""" if not self.items: return retry = 0 options = {"deadline": DATASTORE_DEADLINE} while retry <= self.__timeout_retries: try: self.__flush_function(self.items, options) self.clear() break except db.Timeout, e: logging.warning(e) logging.warning("Flushing '%s' timed out. Will retry for the %s time.", self, retry) retry += 1 options["deadline"] *= 2 except apiproxy_errors.RequestTooLargeError: self._log_largest_items() raise else: raise
def generate_edges_page(ndb_iter, page_size, keys_only, edge_type): edges = [] timeouts = 0 while len(edges) < page_size: try: entity = ndb_iter.next() except StopIteration: break except Timeout: timeouts += 1 if timeouts > 2: break continue except DeadlineExceededError: break if keys_only: # entity is actualy an ndb.Key and we need to create an empty entity to hold it entity = edge_type._meta.fields['node']._type._meta.model(key=entity) edges.append(edge_type(node=entity, cursor=ndb_iter.cursor_after().urlsafe())) return edges
def process_exception(self, request, exception): if isinstance(exception, CapabilityDisabledError): return maintenance(request) elif isinstance(exception, db.Timeout): return server_error(request)