I'm trying to have a grequest spawn additional grequests and I'm finding that the second-level grequest callbacks are not executed. The usecase is to view the first page of results from an api, use it to calculate how many additional pages there are to visit, and then create new grequests for those pages. Here is the relevant code snippet:
def handle_page(response, **kwargs):
# this code is not executed
print(response.url)
print(response.status_code)
def handle_tag(response, **kwargs):
tag = url_to_tag_regex.findall(response.url)[0]
print(tag)
jsonObj = response.json()
totalCount = jsonObj.get("total_count")
totalPages = int(ceil(totalCount / 48.0))
unsent_tag_reqs = (grequests.get(api_url_format % (tag, page),
callback=handle_page,
session=requests_session) for page in xrange(totalPages))
grequests.map(unsent_tag_reqs, size=__CONCURRENT_LIMIT__)
if __name__=="__main__":
unsent_requests = (grequests.get(api_url_format % (tag, 0),
callback=handle_tag,
session=requests_session) for tag in tagList)
grequests.map(unsent_requests, size=__CONCURRENT_LIMIT__)