spyoungtech / grequests

Requests + Gevent = <3
https://pypi.python.org/pypi/grequests
BSD 2-Clause "Simplified" License
4.46k stars 331 forks source link

Grequest returns empty generators #154

Closed MadMowgli closed 2 years ago

MadMowgli commented 2 years ago

I have the following code:

for domain_list in chunks:
    rs = (grequests.get('https://' + url, timeout=timeout) for url in domain_list)
    grequests.map(rs)
    result_list.append(rs)

However, the generators seem to be empty:

for lst in result_list:
    print(len(list(lst)))
0
0
0
0
0

Length check is based on the following stack overflow response: https://stackoverflow.com/a/50645935/10765169

Am I doing something wrong?

shizomontazh commented 2 years ago

Same problem

spyoungtech commented 2 years ago

grequests.map returns the result you're looking for. It will not modify rs.

The corrected version would be something like this:

for domain_list in chunks:
    rs = (grequests.get('https://' + url, timeout=timeout) for url in domain_list)
    results = grequests.map(rs)
    result_list.append(results)