Browse Source

flask_app: 增加数据库连接关闭

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 5 years ago
parent
commit
abf8e80046
2 changed files with 8 additions and 1 deletions
  1. 3 1
      flask_app.py
  2. 5 0
      tongce.py

+ 3 - 1
flask_app.py

@@ -168,8 +168,8 @@ def tongce():
 @app.route('/tongce_data', methods=['GET', 'POST'])
 def tongce_data():
     response = {}
+    tongce = TongCe()
     try:
-        tongce = TongCe()
         tongce.table_type_insert()
         result = tongce.lingdi_data_scores()
         response['code'] = 0
@@ -179,6 +179,8 @@ def tongce_data():
         response['code'] = 1
         response['message'] = '失败:' + str(e)
         return json.dumps(response, ensure_ascii=False)
+    finally:
+        tongce.close()
     return json.dumps(response, ensure_ascii=False)
 
 

+ 5 - 0
tongce.py

@@ -394,6 +394,11 @@ class TongCe:
         self.options_info = ExcelUtil('工作表6', 'tongce.xlsx').read_options_info()
         self.table_type_info = ExcelUtil('新增项目数据项类型排序与展示图表类型管理表', 'table_type.xlsx').get_table_type_info()
 
+    def close(self):
+        self.shangju_db.close()
+        self.linshi_db.close()
+        self.marketing_db.close()
+
     def get_question_info_from_db(self):
         result = self.shangju_db.select(self.sql_2, [67])
         insert_data = []