Grequests-style Concurrency
Send concurrent requests in the style of grequests
The methods async_get, async_post, etc. will create an unsent request. This levereges gevent, making it blazing fast.
Async requests are evaluated on hrequests.map, hrequests.imap, or hrequests.imap_enum.
This functionality is similar to grequests. Unlike grequests, monkey patching is not required because this does not rely on the standard python SSL library.
Create a set of unsent Requests:
>>> reqs = [
... hrequests.async_get('https://www.google.com/', browser='firefox'),
... hrequests.async_get('https://www.duckduckgo.com/'),
... hrequests.async_get('https://www.yahoo.com/')
... ]map
Send them all at the same time using map:
>>> hrequests.map(reqs, size=3)
[<Response [200]>, <Response [200]>, <Response [200]>]imap
imap returns a generator that yields responses as they come in:
imap_enum returns a generator that yields a tuple of (index, response) as they come in. The index is the index of the request in the original list:
Exception Handling
To handle timeouts or any other exception during the connection of the request, you can add an optional exception handler that will be called with the request and exception inside the main thread.
The value returned by the exception handler will be used in place of the response in the result list.
If an exception handler isn't specified, the default yield type is hrequests.FailedResponse.
Last updated