递归urlfetch
2009 11 27 11:26 PM 1937次查看
分类:Google App Engine 标签:Google App Engine, Python
from wsgiref.handlers import CGIHandler
from google.appengine.api import urlfetch
from google.appengine.ext import webapp
class Main(webapp.RequestHandler):
def get(self, times):
times = int(times)
if times:
try:
result = urlfetch.fetch('http://你的app.appspot.com/%s' % (times - 1), deadline=10)
self.response.out.write(result.content)
except:
self.response.out.write(1)
else:
self.response.out.write('0')
application = webapp.WSGIApplication([('/(\d+)', Main)])
def main():
CGIHandler().run(application)
if __name__ == '__main__':
main()
返回0表成功,返回1表失败。当测试数为3(即4层)时一般都会成功,超过则可能失败。最多到9(即10层),也可能是遇到urlfetch的数目限制。
0条评论 你不来一发么↓