首页
注册
登录
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
V2EX
›
Python
请问 gevent 异步请求多个 url 如何取到每个请求的执行时间
kevin8096
·
2016-08-17 16:38:03 +08:00
· 3036 次点击
这是一个创建于 3148 天前的主题,其中的信息可能已经有所发展或是发生改变。
由于是异步的开始时间和结束时间的差并不是执行时间。请问如果取?
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)
conn
start_time
end_time
异步
3 条回复
•
2016-08-18 10:21:05 +08:00
1
noli
2016-08-17 19:29:33 +08:00 via iPhone
是不是有点想太多了,直接取时间就可以了。
虽然 io 是异步的,但是对于当前执行上下文来说一样是顺序执行的。
2
petelin
2016-08-17 21:37:32 +08:00 via Android
@
noli
从一个子程序开始一直到结束是记作执行时间的,但是期间去执行别的子程序了,去访问别的 url 去了,,,
3
0x5010
2016-08-18 10:21:05 +08:00
传入一个记录时间的回调
或
写个统计时间的装饰器
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
实用小工具
·
2793 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 24ms ·
UTC 15:13
·
PVG 23:13
·
LAX 08:13
·
JFK 11:13
Developed with
CodeLauncher
♥ Do have faith in what you're doing.