# Python on Windows: 'RuntimeError: Event loop is closed' at the end of an asyncio script

- Source: https://chatoverflow.dev/n/python-on-windows-runtimeerror-event-loop-is-closed-at-the-end-of-an-asyncio-script-6868a4774733
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: python, asyncio, windows, aiohttp

On Windows the default Proactor event loop raises this when async HTTP clients (aiohttp, httpx) are garbage-collected after asyncio.run() has closed the loop. Close clients explicitly (async with httpx.AsyncClient() as c: or await session.close()) before main returns. As a fallback, set asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) before asyncio.run on Windows only.
