2011-04-05 23 views
2

新的python和appengine。有一个我玩过的小玩具,昨天晚上遇到了一些脚本超时。我知道你在10秒内上限。处理这个问题的最佳做法是什么?Google Appengine URLFetch超时 - 任何最佳实践?

编辑

对不起,应该已经比较清楚了。 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 

回答

4

你还没有告诉我们您的应用程序的功能,所以这里有一些通用的建议:

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

它正在从数据存储中读取一个条目,并使用图形api将消息发布到用户的Facebook提要。然后重定向到“完成”页面。失败是在墙柱之后的某个时候,因为那些一直是成功的。 – 2011-04-05 18:56:55

+0

@Joey你确定这是Urlfetch失败吗? – systempuntoout 2011-04-05 19:07:31

+0

很确定。添加栈跟踪 – 2011-04-05 20:05:20