Skip to content

Values yielded by imap inconsistent with map #111

@spyoungtech

Description

@spyoungtech

Currently, imap will not yield values returned by the exception handler and will not yield None values. However, responses from map will include values returned by the exception handler and will include None values.

Is there any reason why imap shouldn't be consistent with map in this way, at least for the exception handler?

Forgive me if I'm missing something, but I would have thought something like this would be appropriate.

    for request in pool.imap_unordered(send, requests):
        if request.response is not None:
            yield request.response
        elif exception_handler:
            yield exception_handler(request, request.exception)
        else: # probably leave this clause out
            yield None

In other words, a and b should be the same in this example.

import grequests

req_list = [grequests.get('http://fakedomain')]

def ex_handler(req, ex):
    return "foo"

a = grequests.map(req_list, exception_handler=ex_handler)
b = [item for item in grequests.imap(req_list, exception_handler=ex_handler)]

But they are not

>>> a = grequests.map(req_list, exception_handler=ex_handler)
>>> b = [item for item in grequests.imap(req_list, exception_handler=ex_handler)]
>>> a
['foo']
>>> b
[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions