From 0595a87efac0a609ad114727763ac8835c9fc883 Mon Sep 17 00:00:00 2001 From: zy123 <646228430@qq.com> Date: Wed, 19 Feb 2025 16:17:33 +0800 Subject: [PATCH] =?UTF-8?q?2.19=20=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=8B=9B=E6=A0=87=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flask_app/routes/judge_zbfile.py | 17 +++++++++++------ flask_app/start_up.py | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/flask_app/routes/judge_zbfile.py b/flask_app/routes/judge_zbfile.py index 507c36e..ba43a31 100644 --- a/flask_app/routes/judge_zbfile.py +++ b/flask_app/routes/judge_zbfile.py @@ -27,12 +27,17 @@ def judge_zbfile() -> Any: #判断是否是招标文件 unique_id = g.unique_id result = [None] # 用于存储结果的可变对象 done = threading.Event() # 标志判断是否完成 + pool = current_app.process_pool # 使用全局的进程池 def judge_zbfile_exec_sub(file_path): - with multiprocessing.Pool(processes=1) as pool: - result = pool.apply( - judge_zbfile_exec, # 你的实际执行函数 - args=(file_path,) - ) + # with multiprocessing.Pool(processes=1) as pool: + # result = pool.apply( + # judge_zbfile_exec, # 你的实际执行函数 + # args=(file_path,) + # ) + result = pool.apply( + judge_zbfile_exec, # 你的实际执行函数 + args=(file_path,) + ) return result def wrapper() -> None: """ @@ -52,7 +57,7 @@ def judge_zbfile() -> Any: #判断是否是招标文件 logger.info(f"Local file path: {downloaded_filepath}") # 调用实际的判断函数 - judge_result = judge_zbfile_exec(downloaded_filepath) + judge_result = judge_zbfile_exec_sub(downloaded_filepath) judge = JudgeResult.YES if judge_result else JudgeResult.NO end_time = time.time() diff --git a/flask_app/start_up.py b/flask_app/start_up.py index 3106274..23b0fcf 100644 --- a/flask_app/start_up.py +++ b/flask_app/start_up.py @@ -16,6 +16,7 @@ from flask_app.routes.test_preprocess import test_process_bp def create_app(): # 创建全局日志记录器 app = Flask(__name__) + app.process_pool = Pool(processes=5, maxtasksperchild=1) app.global_logger = create_logger_main('model_log') # 全局日志记录器 # 注册蓝图 app.register_blueprint(get_deviation_bp)