我使用Google App Engine开发了一个应用程序,但遇到了问题。 该项目是一个研究项目,我的职能很少。 统计分析,自然语言处理等
很少有功能需要20秒以上才能完成。
其中之一是网站的api,我在其中调用链接并返回字典。 但是,当我调用它时,在4-5秒后,浏览器停止加载并返回一个空值。 而已。
如果我作为简单的python函数在服务器外离线运行该函数,则10-15秒后就会得到结果。
有什么方法可以增加加载时间,还是可以解决我的问题的其他方法?
在Google App Engine中,每个请求的超时时间都是30秒,因此,如果您需要的时间更多,则必须使用Task Queue API或Backends API 。
不过,实现目标的最简单方法不是使用Task Queue API,而是使用延迟的库 ,这对于它来说是一个更简单的包装。 在app.yaml
插入app.yaml
- deferred: on
,您可以执行以下操作(来自文档):
from google.appengine.ext import deferred
def do_something_expensive(a, b, c=None):
logging.info("Doing something expensive!")
# Do your work here
# Somewhere else
deferred.defer(do_something_expensive, "Hello, world!", 42, c=True)
但是,由于任务将在您的请求后完成,因此您可能必须将结果写入数据存储区中的某个位置,以便以后进行检索。
实际上,听起来您是先达到urlFetch超时。
https://developers.google.com/appengine/docs/python/urlfetch/
You can set a deadline for a request, the most amount of time the
service will wait for a response. By default, the deadline for a
fetch is 5 seconds. The maximum deadline is 60 seconds for HTTP
requests and 10 minutes for task queue and cron job requests.
更新:您可以使用截止日期属性进行设置。
https://developers.google.com/appengine/docs/python/urlfetch/fetchfunction