From dd5f88368b026322dc9911f3a5a86da99cd3f0b8 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 28 Oct 2025 21:04:05 +0800 Subject: [PATCH] bugfix --- sqlor/dbpools.py | 21 ++++++++++++++++++--- sqlor/mysqlor.py | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sqlor/dbpools.py b/sqlor/dbpools.py index 1369bdd..992198d 100755 --- a/sqlor/dbpools.py +++ b/sqlor/dbpools.py @@ -56,11 +56,24 @@ class SqlorPool: self.sqlors.append(x) return x + async def _del_sqlor(self, sor): + try: + await sor.exit() + except: + pass + try: + await sor.close() + except: + pass + async def test_sqlor(self, sor): try: + await sor.enter() await sor.execute(sor.test_sqlstr, {}) + await sor.exit() return True except: + await sor.exit() return False @asynccontextmanager @@ -70,10 +83,11 @@ class SqlorPool: yielded_sqlor = None for s in sqlors: if not s.used: - flg = await self.test_sqlor(s) + flg = await self.test_sqlor(s.sqlor) if flg: yielded_sqlor = s else: + await self._del_sqlor(s.sqlor) self.sqlors = [ x for x in self.sqlors if x != s ] if not yielded_sqlor: yielded_sqlor = await self._new_sqlor() @@ -81,6 +95,7 @@ class SqlorPool: yielded_sqlor.use_at = time.time() yield yielded_sqlor.sqlor yielded_sqlor.used = False + @SingletonDecorator class DBPools: @@ -119,9 +134,9 @@ class DBPools: sqlor = None try: async with pool.context() as sqlor: - sqlor.enter() + await sqlor.enter() yield sqlor - sqlor.exit() + await sqlor.exit() if sqlor and sqlor.dataChanged: await sqlor.commit() except Exception as e: diff --git a/sqlor/mysqlor.py b/sqlor/mysqlor.py index 9b00c43..57f4028 100755 --- a/sqlor/mysqlor.py +++ b/sqlor/mysqlor.py @@ -164,7 +164,7 @@ WHERE async def exit(self): try: await self.cur.fetchall() - self.cur.close() + await self.cur.close() except: pass self.cur = None