小编Jam*_*son的帖子

google.appengine.api.urlfetch 截止时间是否限制为 60 秒?

我在谷歌应用程序引擎上使用python,并不断接收google.appengine.api.urlfetch_errors.DeadlineExceededError从进行一些后端处理的机器发出的请求。这些请求大约需要 60 秒,有时会更长一些,因此我尝试延长截止日期。

请求被包装在重试中,从日志中我可以看到重试之间的时间始终约为 60 秒。我认为这要么是因为我配置不正确,要么误解了截止日期的限制。

机器配置为:

instance_class: B8
basic_scaling:
  max_instances: 1
  idle_timeout: 10m
Run Code Online (Sandbox Code Playgroud)

我正在使用的代码是(为简单起见进行了编辑):

from google.appengine.api import urlfetch
from retrying import retry

timeout = 600
retries = 10

@retry(
    stop_max_attempt_number=retries,
    wait_exponential_multiplier=1000,
    wait_exponential_max=1000*60*5
)
def fetch(url):
    """Fetch remote data, retrying as necessary"""
    urlfetch.set_default_fetch_deadline(timeout)
    result = urlfetch.fetch(url)
    if result.status_code != 200:
        raise IOError("Did not receive OK response from server")
    return result.content

data = fetch(config['url'])
Run Code Online (Sandbox Code Playgroud)

我尝试过明确设置截止日期,urlfetch.fetch(url, deadline=timeout)但设置默认值似乎是大多数人建议的方法。

谁能澄清是否可以设置最大值deadline

python google-app-engine google-app-engine-python

5
推荐指数
1
解决办法
1133
查看次数