我意识到有很多关于 grequests 的帖子,例如Asynchronous Requests with Python requests
,它描述了 grequests 的基本用法以及如何通过grequests.get()
我从该链接中提取这段代码来发送钩子。
import grequests
urls = [
'http://python-requests.org',
'http://httpbin.org',
'http://python-guide.org',
'http://kennethreitz.com'
]
# A simple task to do to each response object
def do_something(response):
print ('print_test')
# A list to hold our things to do via async
async_list = []
for u in urls:
action_item = grequests.get(u, hooks = {'response' : do_something})
async_list.append(action_item)
# Do our list of things to do via async
grequests.map(async_list)
当我运行这个但是我没有输出
/$ python test.py
/$
因为有 4 个链接,我希望输出是
print_test
print_test
print_test
print_test
我一直在四处寻找,但无法找到缺少输出的原因,我很有趣的是,我缺少一些关键信息。