推荐学习书目
› 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 · Aug 17, 2016 · 3981 views
    This topic created in 3693 days ago, the information mentioned may be changed or developed.
    由于是异步的开始时间和结束时间的差并不是执行时间。请问如果取?


    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 replies  •  2016-08-18 10:21:05 +08:00
    noli
        1
    noli  
       Aug 17, 2016 via iPhone
    是不是有点想太多了,直接取时间就可以了。
    虽然 io 是异步的,但是对于当前执行上下文来说一样是顺序执行的。
    petelin
        2
    petelin  
       Aug 17, 2016 via Android
    @noli 从一个子程序开始一直到结束是记作执行时间的,但是期间去执行别的子程序了,去访问别的 url 去了,,,
    0x5010
        3
    0x5010  
       Aug 18, 2016
    传入一个记录时间的回调
    或
    写个统计时间的装饰器
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1005 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 17:56 · PVG 01:56 · LAX 10:56 · JFK 13:56
    ♥ Do have faith in what you're doing.