是否可以增加 Google App Engine 中的响应超时?
在我的本地计算机上,脚本运行良好,但在云中它始终为 500。这是一个 cron 任务,所以我真的不介意它是否需要 5 分钟
...... class 'google.appengine.runtime.DeadlineExceededError' >:
知道是否可以增加超时吗?
谢谢, 瑞
On my local machine the script runs fine but in the cloud it 500 all the time. This is a cron task so I don't really mind if it takes 5min...
< class 'google.appengine.runtime.DeadlineExceededError' >:
Any idea whether it's possible to increase the timeout?
Thanks,
rui
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能超过 30 秒,但您可以通过使用任务队列来间接增加超时 - 并编写逐渐迭代数据集并处理它的任务。每个这样的任务运行当然应该符合超时限制。
编辑
更具体地说,您可以使用数据存储区查询游标在同一位置恢复处理:
http://code.google.com/intl/pl/appengine/docs/python/datastore/queriesandindexes.html#Query_Cursors
在 SDK 1.3.1 中首次引入:
< a href="http://googleappengine.blogspot.com/2010/02/app-engine-sdk-131-include-major.html" rel="nofollow noreferrer">http://googleappengine.blogspot.com/2010 /02/app-engine-sdk-131-include-major.html
You cannot go beyond 30 secs, but you can indirectly increase timeout by employing task queues - and writing task that gradually iterate through your data set and processes it. Each such task run should of course fit into timeout limit.
EDIT
To be more specific, you can use datastore query cursors to resume processing in the same place:
http://code.google.com/intl/pl/appengine/docs/python/datastore/queriesandindexes.html#Query_Cursors
introduced first in SDK 1.3.1:
http://googleappengine.blogspot.com/2010/02/app-engine-sdk-131-including-major.html
数据库查询超时的确切规则很复杂,但似乎查询的生存时间不能超过 2 分钟,批处理的生存时间不能超过 30 秒。下面是一些代码,它将一个作业分成多个查询,使用游标来避免这些超时。
The exact rules for DB query timeouts are complicated, but it seems that a query cannot live more than about 2 mins, and a batch cannot live more than about 30 seconds. Here is some code that breaks a job into multiple queries, using cursors to avoid those timeouts.
下面是我用来解决这个问题的代码,将一个大查询分解为多个小查询。我使用
google.appengine.ext.ndb
库 - 我不知道下面的代码是否需要该库才能工作。(如果您没有使用 ndb,请考虑改用它。它是 db 库的改进版本,迁移到它很容易。有关详细信息,请参阅 https://developers.google.com/appengine/docs/python/ndb。)
Below is the code I use to solve this problem, by breaking up a single large query into multiple small ones. I use the
google.appengine.ext.ndb
library -- I don't know if that is required for the code below to work.(If you are not using ndb, consider switching to it. It is an improved version of the db library and migrating to it is easy. For more information, see https://developers.google.com/appengine/docs/python/ndb.)