I am using asyncio and aiohttp to run following asyncronous code but getting this weird error called RuntimeError: Event loop is closed. Though I am getting the desirable results but I am not getting the reason behind this error. I have searched the whole internet but couldent find any relavent resources. I have tried the solution mentioned here , but it didnt work for me.
`
import aiohttp
import asyncio
import time
start_time = time.time()
async def get_pokemon(session, url):
async with session.get(url) as resp:
pokemon = await resp.json()
return pokemon['name']
async def main():
async with aiohttp.ClientSession() as session:
tasks = []
for number in range(1, 15):
url = f'https://pokeapi.co/api/v2/pokemon/{number}'
tasks.append(asyncio.ensure_future(get_pokemon(session, url)))
original_pokemon = await asyncio.gather(*tasks)
for pokemon in original_pokemon:
print(pokemon)
asyncio.run(main())
` My error message
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000000002BCCEB80>
Traceback (most recent call last):
File "C:\Python 38\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Python 38\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Python 38\lib\asyncio\base_events.py", line 719, in call_soon
self._check_closed()
File "C:\Python 38\lib\asyncio\base_events.py", line 508, in _check_closed
raise RuntimeError('Event loop is closed')
It would be really great if someone can help me with this. Thanks