1
This commit is contained in:
parent
f44b67d585
commit
dfb489dd9c
15
v2/db.py
15
v2/db.py
@ -1,5 +1,6 @@
|
||||
__all__ = 'CK',
|
||||
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
import pandas as pd
|
||||
@ -15,12 +16,20 @@ class CK:
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self.__client = self.__create_client()
|
||||
self.look = threading.Lock()
|
||||
|
||||
def __create_client(self):
|
||||
return Client(*self.args, **self.kwargs)
|
||||
|
||||
def execute(self, *args, **kwargs):
|
||||
return self.__client.execute(*args, **kwargs)
|
||||
try:
|
||||
self.look.acquire(timeout=10)
|
||||
res = self.__client.execute(*args, **kwargs)
|
||||
except Exception as e:
|
||||
raise e
|
||||
finally:
|
||||
self.look.release()
|
||||
return res
|
||||
|
||||
def get_one(self, db, tb, try_cnt=3, **where):
|
||||
|
||||
@ -30,7 +39,7 @@ class CK:
|
||||
sql += ' limit 1'
|
||||
data = None
|
||||
try:
|
||||
data, columns = self.__client.execute(sql, with_column_types=True)
|
||||
data, columns = self.execute(sql, with_column_types=True)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
self.__client.disconnect()
|
||||
@ -62,7 +71,7 @@ class CK:
|
||||
sql += where
|
||||
data = None
|
||||
try:
|
||||
data, columns = self.__client.execute(sql, columnar=True, with_column_types=True)
|
||||
data, columns = self.execute(sql, columnar=True, with_column_types=True)
|
||||
except Exception as e:
|
||||
print('*' * 50)
|
||||
print(sql)
|
||||
|
Loading…
Reference in New Issue
Block a user