Event loop is closed Python Origin: Application & API Last updated 14 Oct 2026

RuntimeError: Event loop is closed

Async code tried to use an event loop that has already been shut down.

Exact message you may see Event loop is closedThis event loop is already runningThere is no current event loop
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

  1. Use async with for clients/sessions
  2. Run everything inside a single asyncio.run(main())
  3. On Windows, close clients explicitly before returning

Detailed fix by platform

Python

  1. python
    async with httpx.AsyncClient() as client:
        r = await client.get(url)

How to diagnose

  1. Resource — Which client is cleaned up late?
  2. Pattern — Multiple asyncio.run() calls?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

AbortError — AbortError: The user aborted a request. / signal is aborted without reason (JavaScript)AbortErrorasync useEffect — Warning: useEffect must not return anything besides a function, which is used for clean-up. It looks like you wrote useEffect(async () => ...) (React)async useEffectawait outside async — SyntaxError: await is only valid in async functions and the top level bodies of modules (JavaScript)await outside asyncbody already used — TypeError: Failed to execute 'json' on 'Response': body stream already read (JavaScript)body already usedbroadcast error — ValueError: operands could not be broadcast together with shapes (3,) (4,) (Python)broadcast errorDjango CSRF — Forbidden (403) CSRF verification failed. Request aborted. (Python)Django CSRFexternally-managed-environment — error: externally-managed-environment (Python)externally-managed-en…Flask app context — RuntimeError: Working outside of application context. (Python)Flask app contextEvent loo…

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.