首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google异步-获取100 req/s

Google异步-获取100 req/s
EN

Stack Overflow用户
提问于 2012-02-29 09:10:40
回答 1查看 442关注 0票数 0

我需要得到近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中

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

发布于 2012-02-29 17:22:48

您可以对任务进行排队,然后使用通道API通知并将结果发送给用户。目前,通道只与Javascript客户端一起工作。Google计划在其他语言上实现通道客户端,或者至少为任何想要编写实现的人记录频道客户端。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9496278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档