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