I trying to learn how to use the asyncio framework in Python. I have the below code but it is giving the error:
event loop stopped before the future completed.
Also please update where to capture the outputs of the code.
Code:
import asyncio
import aiopg
dsn = 'dbname=dvdrental user=postgres password=password host=127.0.0.1'
async def go():
pool = await aiopg.create_pool(dsn)
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("Select * from actor")
ret = []
async for row in cur:
ret.append(row)
assert ret == [(1,)]
loop = asyncio.get_event_loop()
loop.run_until_complete(go())