mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #360 from mastahyeti/develop
Make requests.async.send asynchronous
This commit is contained in:
+12
-16
@@ -46,15 +46,15 @@ def patched(f):
|
||||
return wrapped
|
||||
|
||||
|
||||
def send(r, pools=None):
|
||||
"""Sends a given Request object."""
|
||||
def send(r, pool=None):
|
||||
"""Sends the request object using the specified pool. If a pool isn't
|
||||
specified this method blocks. Pools are useful because you can specify size
|
||||
and can hence limit concurrency."""
|
||||
|
||||
if pools:
|
||||
r._pools = pools
|
||||
if pool != None:
|
||||
return pool.spawn(r.send)
|
||||
|
||||
r.send()
|
||||
|
||||
return r.response
|
||||
return gevent.spawn(r.send)
|
||||
|
||||
|
||||
# Patched requests.api functions.
|
||||
@@ -80,17 +80,13 @@ def map(requests, prefetch=True, size=None):
|
||||
|
||||
if size:
|
||||
pool = Pool(size)
|
||||
pool.map(send, requests)
|
||||
pool.join()
|
||||
jobs = [pool.spawn(r.send) for r in requests]
|
||||
else:
|
||||
jobs = [gevent.spawn(send, r) for r in requests]
|
||||
gevent.joinall(jobs)
|
||||
jobs = [gevent.spawn(r.send) for r in requests]
|
||||
|
||||
gevent.joinall(jobs)
|
||||
|
||||
if prefetch:
|
||||
[r.response.content for r in requests]
|
||||
|
||||
return [r.response for r in requests]
|
||||
|
||||
|
||||
|
||||
|
||||
return [r.response for r in requests]
|
||||
Reference in New Issue
Block a user