0

Asynchronous Requests with Python requestsなど、grequest に関する多くの投稿があったことを認識しています。この記事では、grequest の基本的な使用方法やフックを送信する方法について説明しています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

私は周りを検索してきましたが、出力が不足している理由を見つけることができませんでした。私が見逃している重要な情報が少しあることを面白がっています。

4

1 に答える 1