python中的异步请求。
simple-requests的Python项目详细描述
简单的请求允许您获得异步的性能优势 请求,而不需要使用任何异步编码范式。
用法
fromsimple_requestsimportRequests# Creates a session and thread poolrequests=Requests()# Sends one simple request; the response is returned synchronously.login_response=requests.one('http://cat-videos.net/login?user=fanatic&password=c4tl0v3r')# Cookies are maintained in this instance of Requests, so subsequent requests# will still be logged-in.profile_urls=['http://cat-videos.net/profile/mookie','http://cat-videos.net/profile/kenneth','http://cat-videos.net/profile/itchy']# Asynchronously send all the requests for profile pagesforprofile_responseinrequests.swarm(profile_urls):# Asynchronously send requests for each link found on the profile pages# These requests take precedence over those in the outer loop to minimize overall waiting# Order doesn't matter this time either, so turn that off for a performance gainforfriends_responseinrequests.swarm(profile_response.links,maintainOrder=False):# Do something intelligent with the responses, like using# regex to parse the HTML (see http://stackoverflow.com/a/1732454)friends_response.html
发布历史记录
1.1.1(2014年6月27日)
- api更改
- bundleParam参数添加到Requests.one,Requests.swarm,Requests.each
1.1.0(2014年5月1日)
- api更改
- defaultTimeout参数已添加到Requests.__init__
- 错误修复
- 由于gevent 1.0中的api更改而进行的修复
- 修复了几个文档错误
退出时没有错误/警告 - 功能
- 添加了一个patch类,其中包含urllib3的monkey补丁(以减少 立即打开连接/文件)和httplib(忽略错误报告内容长度的服务器)