AsyncIO Paradigm isn’t working in my system as it throws error “Event loop is closed”.
AsyncIO Paradigm
Hey, I am getting the same error , Here is my code:-
import asyncio
import aiohttp
import time
async def fetchfromGoogle():
url="https://www.google.com"
session=aiohttp.ClientSession()
resp=await session.get(url)
await resp.content.read()
await session.close()
async def main():
print(time.strftime('%X'))
await asyncio.gather(
*[
fetchfromGoogle() for _ in range(20)
]
)
print(time.strftime('%X'))
if name==‘main’:
asyncio.run(main())
import asyncio
import aiohttp
import time
async def fetchfromGoogle():
url="https://www.google.com"
session = aiohttp.ClientSession()
resp = await session.get(url)
await resp.content.read()
await session.close()
async def main():
print(time.strftime('%X'))
await asyncio.gather(
*[
fetchfromGoogle() for _ in range(20)
]
)
print(time.strftime('%X'))
if __name__== '__main__':
asyncio.run(main())
I tried this is working fine pls try once again and if doesn’t work then try running your code on https://repl.it/languages/python3 If it works fine then your code is alright may be the system env issues are there.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.