我使用 Google App Engine 开发了一个应用程序,但我遇到了问题。该项目是一个研究项目,我几乎没有繁重的功能。统计分析、自然语言处理等
很少有功能需要超过 20 秒才能完成。
其中一个是网站的 api,我在其中调用链接并返回字典。但是,当我调用它时,4-5 秒后,浏览器停止加载并返回一个空值。而已。
如果我在服务器外离线运行该函数,作为一个简单的 python 函数,我会在 10-15 秒后得到结果。
有什么方法可以增加加载时间或其他可以解决我的问题的方法吗?
我使用 Google App Engine 开发了一个应用程序,但我遇到了问题。该项目是一个研究项目,我几乎没有繁重的功能。统计分析、自然语言处理等
很少有功能需要超过 20 秒才能完成。
其中一个是网站的 api,我在其中调用链接并返回字典。但是,当我调用它时,4-5 秒后,浏览器停止加载并返回一个空值。而已。
如果我在服务器外离线运行该函数,作为一个简单的 python 函数,我会在 10-15 秒后得到结果。
有什么方法可以增加加载时间或其他可以解决我的问题的方法吗?
在 Google App Engine 中,每个请求有 30 秒的硬超时,因此如果您需要更多,则必须使用Task Queue API或Backends API。
实现目标的最简单方法是使用延迟库,而不是乱用任务队列 API,这是一个更简单的包装器。在您插入后- deferred: on
,您app.yaml
可以执行以下操作(来自文档):
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