谷歌应用引擎URLFetch超时-任何最佳实践



python和appengine新功能。我有一个小玩具,我一直在玩,昨晚遇到了一些脚本超时。我知道你的上限是10秒。处理这种情况的最佳实践是什么?

编辑

对不起,我应该说得更清楚些。URLFetch超时是我的问题。默认设置为5秒,最大为10秒

Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 636, in __call__
    handler.post(*groups)
  File "/base/data/home/apps/netlicense/3.349495357411133950/main.py", line 235, in post
    graph.put_wall_post(message=body, attachment=attch, profile_id=self.request.get("fbid"))
  File "/base/data/home/apps/netlicense/3.349495357411133950/facebook.py", line 149, in put_wall_post
    return self.put_object(profile_id, "feed", message=message, **attachment)
  File "/base/data/home/apps/netlicense/3.349495357411133950/facebook.py", line 131, in put_object
    return self.request(parent_object + "/" + connection_name, post_args=data)
  File "/base/data/home/apps/netlicense/3.349495357411133950/facebook.py", line 179, in request
    file = urllib2.urlopen(urlpath, post_data)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 124, in urlopen
    return _opener.open(url, data)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 381, in open
    response = self._open(req, data)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 399, in _open
    '_open', req)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 360, in _call_chain
    result = func(*args)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 1115, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 1080, in do_open
    r = h.getresponse()
  File "/base/python_runtime/python_dist/lib/python2.5/httplib.py", line 197, in getresponse
    self._allow_truncated, self._follow_redirects)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py", line 260, in fetch
    return rpc.get_result()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 592, in get_result
    return self.__get_result_hook(self)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py", line 361, in _get_fetch_result
    raise DeadlineExceededError(str(err))
DeadlineExceededError: ApplicationError: 5

您还没有告诉我们您的应用程序是做什么的,所以这里有一些一般性的建议:

  1. 您可以使用此异常类google.appengine.api.urlfetch.DownloadError捕获超时异常,并轻轻地提醒用户重试。
  2. Web请求运行时间最长为30秒;如果您尝试下载的内容相对较小,则可能会捕获异常并在同一Web请求中重新提交(仅一次)urlfetch。
  3. 如果离线工作对你的应用来说不是问题,你可以把Urlfetch调用移动到一个由任务队列服务的工作任务;使用任务队列API的一个优点是App Engine会自动重试Urlfetch任务,直到它成功。

最新更新