Skip to content
Myr

[enh] async.imap added -- generator object handling

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

authored by asciimoo · committed by asciimoo · parent ea1d5f3 · Browse files · 1 file+23 added−2 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+23 added−2 removed

  • other:+23 added−2 removed

1 file+23 added−2 removed

modified:requests/async.py+23 added-2 removed
21 unmodified lines
22from . import api232425__all__ = (26 'map',26 'map', 'imap',27 'get', 'options', 'head', 'post', 'put', 'patch', 'delete', 'request'28)2930
50 unmodified lines
81 pool = Pool(size) if size else None82 jobs = [send(r, pool, prefetch=prefetch) for r in requests]83 gevent.joinall(jobs)8485 return [r.response for r in requests]85 return [r.response for r in requests]868788def imap(requests, prefetch=True, size=2):89 """Concurrently converts a generator object of Requests to90 a generator of Responses.9192 :param requests: a generator of Request objects.93 :param prefetch: If False, the content will not be downloaded immediately.94 :param size: Specifies the number of requests to make at a time. default is 295 """9697 pool = Pool(size)9899 def send(r):100 r.send(prefetch)101 return r.response102103 for r in pool.imap_unordered(send, requests):104 yield r105106 pool.join()