def map(requests, stream=False, size=None, exception_handler=None):
……
ret = []
for request in requests:
if request.response:
ret.append(request.response)
elif exception_handler:
#exception_handlerrequest, request.exception)
# new code:
ret.append(exception_handler(request))
return ret
And then I can use it like this:
from requests import Response
def timeOutException(request):
if 'ok' in dir(request.response):
return request.response
else:
# build respone for timeout
response = Response()
response.status_code = 444
response.url = request.url
return response
In [119]: res = grequests.map(apprs, exception_handler=timeOutException)
In [120]: res
Out[120]: [<Response [200]>, <Response [444]>, <Response [404]>, <Response [200]>]
eg.
And then I can use it like this:
The same process can also be in imap.