我遇到了一些关于Deadline Exceeded 错误 的问题。基本上,我正在使用 Mechanize 在 URL 中进行一些网络抓取。所以在尝试执行时
br.open(url)
我有这个错误
HTTPException: Deadline exceeded while waiting for HTTP response from URL: my-url
我已阅读 documentation它说要使用Backends(我使用的是动态后端,B4_1G 类有 5 个实例),但在 60 秒内仍然发生此错误。根据文档,当使用 TaskQueue 和 Backends 时,超时应该延长到 10 分钟。
下面是我如何分配要在 TaskQueue 上运行的操作,目标是我的后端的第一个实例。
taskqueue.add(url='/crons/myworker', target='1.myworker')
这是 backends.yaml。
backends:
- name: myworker
class: B4_1G
instances: 5
options: dynamic
对可能发生的事情有什么想法吗?谢谢。
最佳答案
在 App Engine 上,任何涉及通过 HTTP 获取数据的请求都不会超过 60 秒。
10 分钟限制是指任务本身 - 它们最多可以运行 10 分钟。
因此 GAE 可能不是这里的最佳选择,因为如果您的请求平均花费的时间超过 60 秒,您只能使用它提供的 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/
因此,一个任务最多可以运行 10 分钟,而一个 url 提取最多可以运行 60 秒。无论您从前端还是后端执行 urlfetch 操作,限制都是相同的。
关于python - 即使 TaskQueue 在后端运行,也会出现超出截止日期的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20805543/