aio-libs / aio-libs/aiomysql

The latest data cannot be queried when I use the pool

Open
#519 8 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
1.9k
Forks
272
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.