RuntimeError: Event loop is closed
Async code tried to use an event loop that has already been shut down.
Seen on:
Python
Meaning
Common on Windows with asyncio.run() and aiohttp/httpx clients cleaned up after the loop closes, and when mixing asyncio.run() calls with long-lived clients.
Common causes
- Client sessions not closed before the loop ends
- Calling asyncio.run() repeatedly with shared resources
- Windows ProactorEventLoop cleanup noise
⚡ Quick fix
- Use async with for clients/sessions
- Run everything inside a single asyncio.run(main())
- On Windows, close clients explicitly before returning
Detailed fix by platform
Python
- python
async with httpx.AsyncClient() as client: r = await client.get(url)
How to diagnose
- Resource — Which client is cleaned up late?
- Pattern — Multiple asyncio.run() calls?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026