Error handled cursors closing

This commit is contained in:
2025-12-25 21:49:21 +03:00
parent be9f2825df
commit db0d1fb6a5
2 changed files with 20 additions and 8 deletions

View File

@@ -24,8 +24,8 @@ async def close_old_cached_cursors():
continue
try:
await cursor.close()
cached_cursors.pop(cursor_id, None)
await cursor.close()
closed_cached_cursors[cursor_id] = cursor
print(f"Closed cursor {cursor_id}")
except Exception as e:
@@ -51,13 +51,18 @@ async def remove_old_closed_cached_cursors():
async def cached_cursors_cleaner():
global cached_cursors, closed_cached_cursors
while True:
await close_old_cached_cursors()
await remove_old_closed_cached_cursors()
try:
await close_old_cached_cursors()
except Exception as e:
print(f"Error closing some cached cursors, {e=}")
try:
await remove_old_closed_cached_cursors()
except Exception as e:
print(f"Error removing closed cursors, {e=}")
await asyncio.sleep(10)
async def pool_creator(connection: Connection, minsize=5, maxsize=10):
return await aiomysql.create_pool(
host=connection.host,
user=connection.username,