1import asyncio
2import time
3import aiohttp
4
5async def scrape_page(session, url):
6 async with session.get(url) as response:
7 html = await response.text()
8 time.sleep(2) # simulating CPU-heavy parsing
9 return parse(html)
10
11async def scrape_all(urls):
12 async with aiohttp.ClientSession() as session:
13 tasks = [scrape_page(session, url) for url in urls]
14 return await asyncio.gather(*tasks)
no lines flagged
#043PracticeMedium20 min · 120 XP
asyncio Blocking Call in Coroutine
An async web scraper stalls all concurrent coroutines whenever any single page takes time to process.
Flagged linesNo lines flagged yet
Flag a line or write a note to submit.