Python论坛  - 讨论区

标题:Re: Re:[python-chinese]读取http页面耗时的问题

2006年03月21日 星期二 16:42

charles huang hyy at fjii.com
Tue Mar 21 16:42:16 HKT 2006

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过程中。



[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月21日 星期二 19:14

Davies Liu davies.liu at gmail.com
Tue Mar 21 19:14:43 HKT 2006

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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号