From dfb489dd9cf8865c11c8c5daa0debbde9488d8f0 Mon Sep 17 00:00:00 2001 From: wuaho Date: Sat, 14 Aug 2021 15:39:11 +0800 Subject: [PATCH] 1 --- v2/db.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/v2/db.py b/v2/db.py index 4df3bf7..3da4353 100644 --- a/v2/db.py +++ b/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,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: