Browse Source

일발 연결시에도 1초 병목 생기는 현상 수정, 연결 조건 간략화

bass9030 9 months ago
parent
commit
87225237de
1 changed files with 6 additions and 5 deletions
  1. 6 5
      route/tool/func.py

+ 6 - 5
route/tool/func.py

@@ -263,7 +263,7 @@ class get_db_connect:
             self.conn = None
             try_cnt = 1
             max_try = 30
-            while (self.conn == None and not (self.conn.open() if self.conn != None else False)) and try_cnt <= max_try:
+            while self.conn == None and try_cnt <= max_try:
                 try:
                     if self.init_mode:
                         self.conn = pymysql.connect(
@@ -287,16 +287,17 @@ class get_db_connect:
                 except pymysql.err.OperationalError as err:
                     if try_cnt + 1 > max_try:
                         raise err
-                    else:
-                        continue
                 finally:
-                    try_cnt += 1
-                    time.sleep(1)
+                    if self.conn == None:
+                        try_cnt += 1
+                        time.sleep(1)
 
             
             if self.conn == None:
                 raise Exception("Unable to connect database")
 
+        print('DB connected')
+
         return self.conn
     
     def __exit__(self, exc_type, exc_value, traceback):