11 lines
263 B
Python
11 lines
263 B
Python
|
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))
|