stolichki/crawler/utils/asyncio.py

11 lines
263 B
Python
Raw Permalink Normal View History

2024-01-03 14:34:15 +10:00
import asyncio
async def gather_with_concurrency(n, *coros):
semaphore = asyncio.Semaphore(int(n))
async def sem_coro(coro):
async with semaphore:
return await coro
return await asyncio.gather(*(sem_coro(c) for c in coros))