Ömer Şengül

AsyncIO Concurrent Fetch

byÖmer ŞengülCreated February 10, 2024 at 07:00 PM
AsyncIO Concurrent Fetch
1import asyncio
2import aiohttp
3
4async def fetch(session, url):
5    async with session.get(url) as resp:
6        return await resp.text()
7
8async def fetch_all(urls):
9    async with aiohttp.ClientSession() as session:
10        tasks = [fetch(session, url) for url in urls]
11        return await asyncio.gather(*tasks)

Description

Fetch multiple URLs concurrently with asyncio and aiohttp.

Discussion (0)

Sort by: