Let\'s assume we have a bunch of links to download and each of the link may take a different amount of time to download. And I\'m allowed to download using utmost 3 connecti
I used Mikhails answer and ended up with this little gem
async def gather_with_concurrency(n, *tasks):
semaphore = asyncio.Semaphore(n)
async def sem_task(task):
async with semaphore:
return await task
return await asyncio.gather(*(sem_task(task) for task in tasks))
Which you would run instead of normal gather
await gather_with_concurrency(100, *my_coroutines)