> Plain-text rendering of a visual post, for machine consumers.
> Charts, diagrams and images are omitted; their captions are kept inline.
> Titles on collapsible asides are dropped, their contents kept.
> The complete version is at https://abhay.fyi/firing-a-million-async-requests-with-python/

# Firing a million async requests with Python

> This demonstrates how to fire a million async requests with Python.

- Author: Abhay Kashyap (https://abhay.fyi/#person)
- Published: 2022-10-07
- Canonical: https://abhay.fyi/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.

```python

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

- [aiohttp](https://docs.aiohttp.org/en/stable/)