我需要得到近100页在有限的时间和发送结果代码作为回应。Google有一个限制,10异步req在一次。我正在考虑排队,但他们在后台工作,也许收费应用可以帮助?下面是我的代码,当超过14个urls[]失败时:
文件"/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py",第371行,在_get_fetch_result raise (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()发布于 2012-02-29 17:22:48
您可以对任务进行排队,然后使用通道API通知并将结果发送给用户。目前,通道只与Javascript客户端一起工作。Google计划在其他语言上实现通道客户端,或者至少为任何想要编写实现的人记录频道客户端。
https://stackoverflow.com/questions/9496278
复制相似问题