Skip to content
Myr

Merge remote-tracking branch 'origin/develop' into develop

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 843672f, 89266f9 · Browse files · 1 file+1 added−36 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+1 added−36 removed

  • other:+1 added−36 removed

1 file+1 added−36 removed

modified:docs/user/advanced.rst+1 added-36 removed
105 unmodified lines
106107Asynchronous Requests108----------------------109110Requests has first-class support for concurrent requests, powered by gevent.111This allows you to send a bunch of HTTP requests at the same time.110113First, let's import the async module. Heads up — if you don't have114`gevent <http://pypi.python.org/pypi/gevent>`_ this will fail::111``requests.async`` has been removed from requests and is now its own repository named `GRequests <https://github.com/kennethreitz/grequests>`_.112116 from requests import async113118The ``async`` module has the exact same api as ``requests``, except it119doesn't send the request immediately. Instead, it returns the ``Request``120object.121122We can build a list of ``Request`` objects easily::123124 urls = [125 'http://python-requests.org',126 'http://httpbin.org',127 'http://python-guide.org',128 'http://kennethreitz.com'129 ]130131 rs = [async.get(u) for u in urls]132133Now we have a list of ``Request`` objects, ready to be sent. We could send them134one at a time with ``Request.send()``, but that would take a while. Instead,135we'll send them all at the same time with ``async.map()``. Using ``async.map()``136will also guarantee execution of the ``response`` hook, described below. ::137138 >>> responses = async.map(rs)139 >>> responses140 [<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>]141142.. admonition:: Throttling143144 The ``map`` function also takes a ``size`` parameter, that specifies the number of connections to make at a time::145146 async.map(rs, size=5)147148114Event Hooks115-----------116117Requests has a hook system that you can use to manipulate portions of
336 unmodified lines