如何在 Google App Engine 中为 urlfetch 设置超时? [英] How to set timeout for urlfetch in Google App Engine?
问题描述
我正在尝试让 Django(在 GAE 之上)从另一个 Web 服务获取数据.我经常遇到这样的错误:
I'm trying to have Django (on top of GAE) fetch data from another web service. I'm often hit with error like this:
ApplicationError: 2 超时请求
ApplicationError: 2 timed out Request
方法:获取
异常类型:下载错误
异常值:ApplicationError:2 超时
Exception Value: ApplicationError: 2 timed out
异常位置:/google_appengine/google/appengine/api/urlfetch.py in _get_fetch_result,第 325 行
Exception Location: /google_appengine/google/appengine/api/urlfetch.py in _get_fetch_result, line 325
感觉好像它会在 12 秒后超时(我不确定,但真的很短).
It feels as if it will time out only after 12 seconds (I'm not sure, but it's really short).
问题:如何设置更长的超时时间?
推荐答案
You can set it using the deadline
argument of the fetch function. From the docs:
请求处理程序的截止时间最长为 60 秒,任务队列和 Cron 作业处理程序的截止时间最长为 10 分钟.如果截止时间为 None,则截止时间设置为 5 秒.
The deadline can be up to a maximum of 60 seconds for request handlers and 10 minutes for tasks queue and cron job handlers. If deadline is None, the deadline is set to 5 seconds.
<小时>
现在看起来已经改变了.从此处:
looks like this has changed now. From here:
您可以为请求设置截止时间,即服务等待响应的最长时间.默认情况下,获取的截止时间为 5 秒.您可以使用 urlfetch.set_default_fetch_deadline()
函数调整请求的默认截止日期.
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. You can adjust the default deadline for requests using the
urlfetch.set_default_fetch_deadline()
function.
并且此页面列出了默认超时值:
And this page lists the default timeout values:
目前,Python 运行时有几个名为 DeadlineExceededError 的错误:
Currently, there are several errors named DeadlineExceededError for the Python runtime:
google.appengine.runtime.DeadlineExceededError
:在整个请求超时时引发,通常在 60 秒后或任务队列请求 10 分钟后.google.appengine.runtime.apiproxy_errors.DeadlineExceededError
:如果 RPC 超过其截止日期,则会引发.这通常是 5 秒,但可以使用截止日期"选项为某些 API 设置.google.appengine.api.urlfetch_errors.DeadlineExceededError
:在 URLFetch 超时时引发.
google.appengine.runtime.DeadlineExceededError
: raised if the overall request times out, typically after 60 seconds, or 10 minutes for task queue requests.google.appengine.runtime.apiproxy_errors.DeadlineExceededError
: raised if an RPC exceeded its deadline. This is typically 5 seconds, but it is settable for some APIs using the 'deadline' option.google.appengine.api.urlfetch_errors.DeadlineExceededError
: raised if the URLFetch times out.
这篇关于如何在 Google App Engine 中为 urlfetch 设置超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!