bugfix
This commit is contained in:
parent
84d740ad3d
commit
dd5f88368b
@ -56,11 +56,24 @@ class SqlorPool:
|
|||||||
self.sqlors.append(x)
|
self.sqlors.append(x)
|
||||||
return 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):
|
async def test_sqlor(self, sor):
|
||||||
try:
|
try:
|
||||||
|
await sor.enter()
|
||||||
await sor.execute(sor.test_sqlstr, {})
|
await sor.execute(sor.test_sqlstr, {})
|
||||||
|
await sor.exit()
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
|
await sor.exit()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
@ -70,10 +83,11 @@ class SqlorPool:
|
|||||||
yielded_sqlor = None
|
yielded_sqlor = None
|
||||||
for s in sqlors:
|
for s in sqlors:
|
||||||
if not s.used:
|
if not s.used:
|
||||||
flg = await self.test_sqlor(s)
|
flg = await self.test_sqlor(s.sqlor)
|
||||||
if flg:
|
if flg:
|
||||||
yielded_sqlor = s
|
yielded_sqlor = s
|
||||||
else:
|
else:
|
||||||
|
await self._del_sqlor(s.sqlor)
|
||||||
self.sqlors = [ x for x in self.sqlors if x != s ]
|
self.sqlors = [ x for x in self.sqlors if x != s ]
|
||||||
if not yielded_sqlor:
|
if not yielded_sqlor:
|
||||||
yielded_sqlor = await self._new_sqlor()
|
yielded_sqlor = await self._new_sqlor()
|
||||||
@ -81,6 +95,7 @@ class SqlorPool:
|
|||||||
yielded_sqlor.use_at = time.time()
|
yielded_sqlor.use_at = time.time()
|
||||||
yield yielded_sqlor.sqlor
|
yield yielded_sqlor.sqlor
|
||||||
yielded_sqlor.used = False
|
yielded_sqlor.used = False
|
||||||
|
|
||||||
|
|
||||||
@SingletonDecorator
|
@SingletonDecorator
|
||||||
class DBPools:
|
class DBPools:
|
||||||
@ -119,9 +134,9 @@ class DBPools:
|
|||||||
sqlor = None
|
sqlor = None
|
||||||
try:
|
try:
|
||||||
async with pool.context() as sqlor:
|
async with pool.context() as sqlor:
|
||||||
sqlor.enter()
|
await sqlor.enter()
|
||||||
yield sqlor
|
yield sqlor
|
||||||
sqlor.exit()
|
await sqlor.exit()
|
||||||
if sqlor and sqlor.dataChanged:
|
if sqlor and sqlor.dataChanged:
|
||||||
await sqlor.commit()
|
await sqlor.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -164,7 +164,7 @@ WHERE
|
|||||||
async def exit(self):
|
async def exit(self):
|
||||||
try:
|
try:
|
||||||
await self.cur.fetchall()
|
await self.cur.fetchall()
|
||||||
self.cur.close()
|
await self.cur.close()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.cur = None
|
self.cur = None
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user