python - 即使 TaskQueue 在后端运行,也会出现超出截止日期的错误

标签 python google-app-engine

我遇到了一些关于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 秒内仍然发生此错误。根据文档,当使用 TaskQueueBackends 时,超时应该延长到 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/

相关文章:

python - 有效地计算数组中 N 个最小数字的总和

python - 如何扩展/修补现有模块或包?

google-app-engine - Go Appengine 教程是否缺少 LoginURL 重定向语句?

android - Google Cloud Endpoint 不断抛出 "unexpected end of stream"异常

Python:无法从 init 文件导入在 setUp 方法中初始化的全局变量

python - 窗口不出现

google-app-engine - Google App Engine - get_serving_url - 如何在收到 DMCA 删除通知时立即删除对图像的访问权限?

python - Google App-Engine 为自己的 Python 应用程序运行 setup.py install

google-app-engine - Google App Engine - 接收邮件(带附件)是否会收取传入带宽费用?

Python eval 字符串中的整数,并返回整数而不是 ascii 字符