Skip to content
Myr

Merge pull request #360 from mastahyeti/develop

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

Make requests.async.send asynchronous

authored by Kenneth Reitz · committed by Kenneth Reitz · parents df0dc2b, e38046e · Browse files · 1 file+12 added−16 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+12 added−16 removed

  • other:+12 added−16 removed

1 file+12 added−16 removed

modified:requests/async.py+12 added-16 removed
44 unmodified lines
4546 return wrapped474849def send(r, pools=None):50 """Sends a given Request object."""49def send(r, pool=None):50 """Sends the request object using the specified pool. If a pool isn't 51 specified this method blocks. Pools are useful because you can specify size52 and can hence limit concurrency."""5352 if pools:53 r._pools = pools54 if pool != None:55 return pool.spawn(r.send)5655 r.send()57 return gevent.spawn(r.send)5857 return r.response595960# Patched requests.api functions.61get = patched(api.get)62options = patched(api.options)63head = patched(api.head)
15 unmodified lines
79 requests = list(requests)8081 if size:82 pool = Pool(size)83 pool.map(send, requests)84 pool.join()83 jobs = [pool.spawn(r.send) for r in requests]84 else:86 jobs = [gevent.spawn(send, r) for r in requests]87 gevent.joinall(jobs)85 jobs = [gevent.spawn(r.send) for r in requests]86 87 gevent.joinall(jobs)8889 if prefetch:90 [r.response.content for r in requests]9192 return [r.response for r in requests]9394959692 return [r.response for r in requests]