ck 连接池
This commit is contained in:
parent
773e1fac82
commit
adf440f977
@ -5,13 +5,13 @@ import pandas as pd
|
|||||||
|
|
||||||
|
|
||||||
class CKDrive:
|
class CKDrive:
|
||||||
ClientPool = dict()
|
ClientPool = set()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _execute(cls, *args, **kwargs):
|
async def _execute(cls, *args, **kwargs):
|
||||||
key, client = cls.ClientPool.popitem()
|
client = cls.ClientPool.pop()
|
||||||
res = await client.execute(*args, **kwargs)
|
res = await client.execute(*args, **kwargs)
|
||||||
CKDrive.ClientPool[key] = client
|
CKDrive.ClientPool.add(client)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
async def execute(self, sql) -> dict:
|
async def execute(self, sql) -> dict:
|
||||||
|
@ -7,8 +7,9 @@ from .ckdb import CKDrive
|
|||||||
async def connect_to_ck(pool_size=100):
|
async def connect_to_ck(pool_size=100):
|
||||||
for i in range(pool_size):
|
for i in range(pool_size):
|
||||||
client = Client(**settings.CK_CONFIG)
|
client = Client(**settings.CK_CONFIG)
|
||||||
CKDrive.ClientPool[i] = client
|
CKDrive.ClientPool.add(client)
|
||||||
|
|
||||||
|
|
||||||
async def close_ck_connection():
|
async def close_ck_connection():
|
||||||
await CKDrive.client.disconnect()
|
for c in CKDrive.ClientPool:
|
||||||
|
await c.disconnect()
|
||||||
|
Loading…
Reference in New Issue
Block a user