def imap(requests, stream=False, size=2, exception_handler=None):
 pool = Pool(size)
 def send(r):
  return r.send(stream=stream)
 for request in pool.imap_unordered(send, requests):
  if (request.response is not None):
   (yield request.response)
  elif exception_handler:
   exception_handler(request, request.exception)
 pool.join()

def imap ( requests , stream = False , size = 2 , exception_handler = None ) : pool = Pool ( size ) def send ( r ) : return r . send ( stream = stream ) for request in pool . imap_unordered ( send , requests ) : if ( request . response is not None ) : ( yield request . response ) elif exception_handler : exception_handler ( request , request . exception ) pool . join ( )
concurrently converts a generator object of requests to a generator of responses .