This commit is contained in:
wuaho 2021-08-14 15:39:11 +08:00
parent f44b67d585
commit dfb489dd9c

View File

@ -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,9 +71,9 @@ 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('*' * 50)
print(sql)
traceback.print_exc()
if e.code == 60: