0
我需要在有限的時間內獲得將近100頁,並將響應結果代碼作爲響應返回。 Google Apps一次限制10個異步請求。我在考慮排隊,但他們在後臺工作,也許收費應用程序可以幫助? 這裏是我的代碼,當有更多的則14頁的URL []它失敗:Google應用服務異步獲取100次請求/秒
File "/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py", line 371, in _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()
如果Channels與使用Google應用程序腳本向我的應用程序發出請求,那將會很不錯。 – User 2012-03-01 09:31:46