{"id":976,"hash":"a0619c3d8359744a54763b28ede2a15f34812ee7fcf439389b41ec3e461faf7f","pattern":"Asyncio RuntimeError: Event Loop is Closed","full_message":"I'm trying to make a bunch of requests (~1000) using Asyncio and the aiohttp library, but I am running into a problem that I can't find much info on.\n\nWhen I run this code with 10 urls, it runs just fine. When I run it with 100+ urls, it breaks and gives me RuntimeError: Event loop is closed error.\n\nimport asyncio\nimport aiohttp\n\n@asyncio.coroutine\ndef get_status(url):\n    code = '000'\n    try:\n        res = yield from asyncio.wait_for(aiohttp.request('GET', url), 4)\n        code = res.status\n        res.close()\n    except Exception as e:\n        print(e)\n    print(code)\n\nif __name__ == \"__main__\":\n    urls = ['https://google.com/'] * 100\n    coros = [asyncio.Task(get_status(url)) for url in urls]\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(asyncio.wait(coros))\n    loop.close()\n\nThe stack trace can be found here.\n\nAny help or insight would be greatly appreciated as I've been banging my head over this for  a few hours now. Obviously this would suggest that an event loop has been closed that should still be open, but I don't see how that is possible.","ecosystem":"pypi","package_name":"python-3.x","package_version":null,"solution":"You're right, loop.getaddrinfo uses a ThreadPoolExecutor to run socket.getaddrinfo in a thread.\n\nYou're using asyncio.wait_for with a timeout, which means res = yield from asyncio.wait_for... will raise a asyncio.TimeoutError after 4 seconds. Then the get_status coroutines return None and the loop stops. If a job finishes after that, it will try to schedule a callback in the event loop and raises an exception since it is already closed.","confidence":0.85,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/32598231/asyncio-runtimeerror-event-loop-is-closed","votes":24,"created_at":"2026-04-19T04:52:07.351580+00:00","updated_at":"2026-04-19T04:52:07.351580+00:00"}