aio-libs / aio-libs/aiomysql

The latest data cannot be queried when I use the pool

未關閉
#519 8 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
question
主要語言
Python
星號
1.9k
分支
272
PR 合併指標
30 天內沒有已合併 PR

描述

When I use the connection pool, I add or modify data to the database, and then get a connection from the connection pool to query. The resulting data is still old data.
like this:
```python
loop = asyncio.get_event_loop()
async def go():
pool = await aiomysql.create_pool(host='127.0.0.1', port=3306,
user='root', password='xxx',
db='study', loop=loop)
while True:
await asyncio.sleep(2)
async with pool.acquire() as conn: # type: aiomysql.Connection
async with conn.cursor() as cur:
await cur.execute("SELECT nickname FROM tb_user ORDER BY id DESC LIMIT 1")
# print(cur.description)
(r,) = await cur.fetchone()
print(r)
print(pool.size)

loop.run_until_complete(go())
```

When I change the way I write it he can normally query the new data.
like this:
```python
loop = asyncio.get_event_loop()
async def go():
pool = await aiomysql.create_pool(host='127.0.0.1', port=3306,
user='root', password='xxx',
db='study', loop=loop)
while True:
await asyncio.sleep(1)
async with await pool.acquire() as conn: # type: aiomysql.Connection
async with conn.cursor() as cur:
await cur.execute("SELECT nickname FROM tb_user ORDER BY id DESC LIMIT 1")
# print(cur.description)
(r,) = await cur.fetchone()
pool.release(conn)
print(r)
print(pool.size)

loop.run_until_complete(go())

```
But then I got a warning:
```
An open stream object is being garbage collected; call "stream.close()" explicitly.
```
I don't know how to get real-time update data from the database in the connection pool normally.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。