我需要在有限的时间内获得近100页,并将结果代码作为回复发送。 Google Apps一次性限制为10个异步请求。我正在考虑队列,但他们在后台工作,也许可计费的应用程序可以帮助? 这是我的代码,当有超过14个urls []它失败时:
文件 “/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py” 第371行,在_get_fetch_result中 raise DeadlineExceededError(str(err))DeadlineExceededError:ApplicationError:5
class MainPage(webapp.RequestHandler):
results = []
urls = [ "http://google.com/",
"http://yahoo.com",
"http://goo.gl",
"http://stackoverflow.com",
"http://windows.com",
"http://wikipedia.org"
]
counter = len(urls)
def handle_result(self, rpc, rowIndex):
self.counter -= 1
result = rpc.get_result()
if result:
self.results.append(str(rowIndex)+": "+str(result.status_code)+"<br>")
if not self.counter:
self.response.out.write("".join(self.results))
def create_callback(self, rpc, rowIndex):
return lambda: self.handle_result(rpc, rowIndex)
def get(self):
rpcs = []
rowIndex = 0
for url in self.urls:
rpc = urlfetch.create_rpc(deadline = 10)
rpc.callback = self.create_callback(rpc, rowIndex)
urlfetch.make_fetch_call(rpc, url)
rpcs.append(rpc)
rowIndex += 1
# Finish all RPCs, and let callbacks process the results.
for rpc in rpcs:
rpc.wait()
答案 0 :(得分:0)
您可以将任务排入队列,然后使用channel API通知并将结果发送给用户。目前,渠道仅适用于Javascript客户端。谷歌计划用其他语言实现渠道客户,或者至少为任何想要编写实施方案的人记录渠道客户端。