Firing a million async requests with Python


There is no reason you'd ever need to fire a million requests to a single server so don't do this. like totally. don't. do. this.

import asyncio
import aiohttp

async def get_stuph(url, session, i):
    print(f"Firing request #{i}. brrr.")
    await session.get(url)

async def main():
    url = "http://some_url.nope"
    async with aiohttp.ClientSession() as session:
        _ = await asyncio.gather(
            *[
                get_stuph(url, session, i)
                for i in range(1_000_000)
            ]
        )

asyncio.run(main())

References