I already wrote my script using asyncio but found that the number of coroutines running simultaneously is too large and it often ends up hanging around.
So I would like
I can suggest using asyncio.BoundedSemaphore.
import asyncio
async def my_func(player, asyncio_semaphore):
async with asyncio_semaphore:
# do stuff
async def main():
asyncio_semaphore = asyncio.BoundedSemaphore(200)
jobs = []
for i in range(12000):
jobs.append(asyncio.ensure_future(my_func(players[i], asyncio_semaphore)))
await asyncio.gather(*jobs)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.set_debug(True)
loop.run_until_complete(main())
This way, only 200 concurrent tasks can acquire semaphore and use system resources while 12000 tasks are at hand.