-
-
Notifications
You must be signed in to change notification settings - Fork 206
Closed
Description
If the async query is running in the thread and the connection is explicitly closed, the ongoing execution doesn't get terminated (we can still see the process in the terminal). Also, the execute function ( await _c.execute("SELECT pg_sleep(20);")) runs indefinitely.
Here is the test code:
async def test_connect():
conn = await AsyncConnection.connect(
host='localhost',
port=5432,
dbname='db1',
user='postgres',
password='xxxxxx'
)
return conn
conn = asyncio.run(test_connect())
_cur = _cursor(conn)
def asyn_exec_query(c):
try:
async def _execute(_c):
print("Execution Start.")
await _c.execute("SELECT pg_sleep(20);")
print("Execution Complete.")
asyncio.run(_execute(c))
except Exception as e:
print(str(e))
async def main():
_thread = threading.Thread(target=asyn_exec_query, args=(_cur,))
_thread.start()
print("Before Sleep")
time.sleep(3)
print("After sleep")
await conn.close()
print("Finish")
asyncio.run(main())
Metadata
Metadata
Assignees
Labels
No labels