I wrote the following code:
import eventlet
import requests
import redis
redis = redis.StrictRedis(host="localhost", port="6379", db=0)
proxy_1_pool = eventlet.GreenPool(40)
def fetch_items():
for _ in range(0, 400):
proxy_1_pool.spawn(fetch_listing)
proxy_1_pool.waitall()
def fetch_listing():
logger.info("START fetch: " + str(datetime.utcnow()))
url_info = redis.spop("listings_to_crawl")
content = make_request(url_info)
logger.info("END fetch: " + str(datetime.utcnow()))
if content:
do_something(content)
def make_request(url_info):
r = requests.get(url_info)
return r.content
def main():
fetch_items()
Unfortunately I see that fetch_listing is being involved sequentially.
It would always print:
START
END
START
END
While I would expect to see:
START
START
END
END