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
kevin8096
V2EX  ›  Python

请问 gevent 异步请求多个 url 如何取到每个请求的执行时间

  •  
  •   kevin8096 · 2016-08-17 16:38:03 +08:00 · 2738 次点击
    这是一个创建于 2780 天前的主题,其中的信息可能已经有所发展或是发生改变。
    由于是异步的开始时间和结束时间的差并不是执行时间。请问如果取?


    start_time = func.millisecond()
    conn = httplib.HTTPConnection(self.host,timeout=5)
    conn.putrequest("GET", "/")
    conn.putheader("Host", self.domain)
    conn.endheaders()
    res = conn.getresponse()
    end_time = func.millisecond()
    use_time = str(end_time - start_time)
    3 条回复    2016-08-18 10:21:05 +08:00
    noli
        1
    noli  
       2016-08-17 19:29:33 +08:00 via iPhone
    是不是有点想太多了,直接取时间就可以了。
    虽然 io 是异步的,但是对于当前执行上下文来说一样是顺序执行的。
    petelin
        2
    petelin  
       2016-08-17 21:37:32 +08:00 via Android
    @noli 从一个子程序开始一直到结束是记作执行时间的,但是期间去执行别的子程序了,去访问别的 url 去了,,,
    0x5010
        3
    0x5010  
       2016-08-18 10:21:05 +08:00
    传入一个记录时间的回调

    写个统计时间的装饰器
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1187 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 18:16 · PVG 02:16 · LAX 11:16 · JFK 14:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.