2006年03月21日 星期二 16:42
jacob,您好! 呵呵,贴代码的时候分成两个邮件了,让大家误解了,完整的代码如下: conn = httplib.HTTPConnection(self.stc.svc_domain) for j in xrange(3): try: time_begin = time.time() conn.request("GET",self.stc.svc_page) time_end = time.time() time_cost = round(time_end - time_begin, 4) except: self.stc.svc_stat = "Error" time.sleep(2) continue response_ob = conn.getresponse() if response_ob.reason == 'OK': self.stc.svc_stat = 'OK' time_begin = time.time() page_len = len(response_ob.read()) time_end = time.time() time_cost = time_cost + round(time_end - time_begin, 4) break else: 而且,根据实际运行代码的情况,read()其实并不耗什么时间,主要耗时是在request过程中。
2006年03月21日 星期二 19:14
On 3/21/06, charles huang <hyy at fjii.com> wrote: > > jacob,您好! > > 呵呵,贴代码的时候分成两个邮件了,让大家误解了,完整的代码如下: > > conn = httplib.HTTPConnection(self.stc.svc_domain) > for j in xrange(3): > try: > time_begin = time.time() 此处开始计时没错 conn.request("GET",self.stc.svc_page) > time_end = time.time() > time_cost = round(time_end - time_begin, 4) > except: > self.stc.svc_stat = "Error" > time.sleep(2) > continue > response_ob = conn.getresponse() > if response_ob.reason == 'OK': > self.stc.svc_stat = 'OK' > time_begin = time.time() > page_len = len(response_ob.read()) 应该在这里结束计时,且只使用一个计时器 time_end = time.time() > time_cost = time_cost + round(time_end - time_begin, 4) > break > else: > > 而且,根据实际运行代码的情况,read()其实并不耗什么时间,主要耗时是在request过程中。 > > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- Davies Liu My Blog: http://blog.daviesliu.net/ My MSN: davies616 at msn.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060321/62322cdd/attachment-0001.html
Zeuux © 2025
京ICP备05028076号