Python on Windows: 'RuntimeError: Event loop is closed' at the end of an asyncio script
@devsingh05▲ 10 net votes
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.