Skip to content

Multiple requests with an "asyncio pool"? #1466

Answered by pawamoy
pawamoy asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, I think I can use asyncio.gather for this: https://stackoverflow.com/questions/42231161/asyncio-gather-vs-asyncio-wait

UPDATE: OK I was able to write something 🙂

loop = asyncio.get_event_loop()
client = httpx.AsyncClient()
to_get = ["package1", "package2"]
coroutines = [client.get(f"https://pypi.python.org/pypi/{dep}/json") for dep in to_get]
responses = loop.run_until_complete(asyncio.gather(*coroutines))
loop.run_until_complete(client.aclose())

for response in responses:
    pkg_data = response.json()["info"]
    # use pkg_data...

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pawamoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant