rui*_*rui 5 python google-app-engine timeout exception cron-task
在我的本地机器上,脚本运行正常,但在云端它一直运行500.这是一个cron任务,所以我真的不介意它是否需要5分钟......
<class'google.appengine.runtime.DeadlineExceededError'>:
不知道是否可以增加超时?
谢谢,瑞
您不能超过30秒,但可以通过使用任务队列间接增加超时 - 并编写逐步遍历数据集并处理它的任务.每个这样的任务运行当然应该符合超时限制.
更具体地说,您可以使用数据存储区查询游标在同一位置继续处理:
http://code.google.com/intl/pl/appengine/docs/python/datastore/queriesandindexes.html#Query_Cursors
首先在SDK 1.3.1中介绍:
http://googleappengine.blogspot.com/2010/02/app-engine-sdk-131-including-major.html
数据库查询超时的确切规则很复杂,但似乎查询的生存时间不能超过2分钟,批处理的生存时间不能超过30秒.下面是一些将作业分解为多个查询的代码,使用游标来避免这些超时.
def make_query(start_cursor):
query = Foo()
if start_cursor:
query.with_cursor(start_cursor)
return query
batch_size = 1000
start_cursor = None
while True:
query = make_query(start_cursor)
results_fetched = 0
for resource in query.run(limit = batch_size):
results_fetched += 1
# Do something
if results_fetched == batch_size:
start_cursor = query.cursor()
break
else:
break
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4382 次 |
最近记录: |