Python 如何在繁重的查询中处理60秒超时

Python 如何在繁重的查询中处理60秒超时,python,google-app-engine,google-cloud-datastore,Python,Google App Engine,Google Cloud Datastore,我必须在我的数据存储中进行一些繁重的查询,以获取一些高级信息。当它达到60秒时,我得到一个错误,我认为这是超时切断: Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 207, in Handle result = handler(dict(self._environ), self._Star

我必须在我的数据存储中进行一些繁重的查询,以获取一些高级信息。当它达到60秒时,我得到一个错误,我认为这是超时切断:

Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 207, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/admin/__init__.py", line 140, in xsrf_required_decorator
method(self)
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/admin/__init__.py", line 348, in post
exec(compiled_code, globals())
File "<string>", line 28, in <module>
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 2314, in next
return self.__model_class.from_entity(self.__iterator.next())
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 1442, in from_entity
return cls(None, _from_entity=entity, **entity_values)
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 958, in __init__
if isinstance(_from_entity, datastore.Entity) and _from_entity.is_saved():
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 814, in is_saved
self.__key.has_id_or_name())
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore_types.py", line 565, in has_id_or_name
elems = self.__reference.path().element_list()
DeadlineExceededError
这不是应用程序查询,我通过交互控制台与我的应用程序交互,因此这不是一个实际问题。我的问题是,我必须迭代我的所有应用程序用户,检查我需要为每个用户检索的大量数据。我可以通过硬编码他们的用户id一个接一个地完成,但这样做既慢又没有效率

你们能想个办法让我快点吗?不管怎样,是否可以选择5乘5的用户,比如LIMIT=5只获取前5个用户,但是如果我能够获取,首先是5个用户,然后是接下来的5个用户,以此类推,对所有用户进行迭代,但使用更轻的查询,那就太好了。我可以设置更长的超时时间吗


你能想到我能解决这个问题的方法吗?

你可以使用光标在你停止搜索的地方与“限制”:

返回base64编码的游标字符串,该字符串表示在检索到的最后一个结果之后查询结果集中的位置。游标字符串可以安全地用于HTTP GET和POST参数,也可以存储在数据存储或Memcache中。将来对同一查询的调用可以通过start\u cursor参数或with\u cursor方法提供此字符串,以继续从此位置检索结果


我会编写一个简单的请求处理程序来完成这项任务


要么以可以在mapreduce上运行的方式编写,要么启动后端来运行处理程序。

首先,通过批量获取实体,将显著减少应用程序与数据存储的通信时间。有关这方面的详细信息,请参阅

然后,您可以将此过程分配给任务队列,使您能够在10分钟内执行任务。有关任务队列的更多信息,请参阅

最后,对于需要更多时间的任务,你也可以考虑后端的使用。有关更多信息,请查看


希望这能有所帮助。

相关:你试过远程API了吗?我还没有试过远程API,它能提供解决方案吗?这可能就是我想要的,我应该去看看