V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Livid
V2EX  ›  Python

Requests 有可能像 PyCURL 那样拿到各个阶段的耗时么:DNS 时间,连接时间,下载时间……

  •  
  •   Livid · 2013-11-03 03:16:46 +08:00 · 4605 次点击
    这是一个创建于 3827 天前的主题,其中的信息可能已经有所发展或是发生改变。
    4 条回复    1970-01-01 08:00:00 +08:00
    9hills
        1
    9hills  
       2013-11-03 08:47:50 +08:00
    我瞅了瞅requests的代码,貌似不能。requests自己实现了一个urllib3做底层

    PyCURL是怎么拿到的?
    est
        2
    est  
       2013-11-03 10:08:58 +08:00
    可以拿到,需要hack。

    DNS时间 -> socket 不直接 connect(), 先 gethostbyname(),计时得到

    连接时间 -> socket 去connect() 直连IP用个计时

    请求时间 -> socket 去send()计时

    返回时间 -> socket.recv() 计时
    lovesky
        3
    lovesky  
       2013-11-03 18:06:55 +08:00
    @est 我想这里的Requests应该指的是这个:Requests: HTTP for Humans

    http://www.python-requests.org/en/latest/
    https://pypi.python.org/pypi/requests
    est
        4
    est  
       2013-11-03 19:16:23 +08:00
    @lovesky 知道。。。python里边的对象都是可以hook的。


    import socket

    socket = 1
    import requests

    然后你试试还能用requests不?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2871 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:51 · PVG 20:51 · LAX 05:51 · JFK 08:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.