Spaces:
Sleeping
Sleeping
朱东升
commited on
Commit
·
e74db4f
1
Parent(s):
64ec244
requirements update16
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import os
|
|
5 |
import sys
|
6 |
from pathlib import Path
|
7 |
import concurrent.futures
|
|
|
8 |
|
9 |
# 添加当前目录和src目录到模块搜索路径
|
10 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
@@ -29,8 +30,10 @@ def evaluate(input_data):
|
|
29 |
return {"status": "Exception", "error": "Input must be a list"}
|
30 |
|
31 |
results = []
|
32 |
-
#
|
33 |
-
|
|
|
|
|
34 |
# 提交所有任务到线程池
|
35 |
future_to_item = {executor.submit(evaluate_single_case, item): item for item in input_data}
|
36 |
# 获取结果
|
|
|
5 |
import sys
|
6 |
from pathlib import Path
|
7 |
import concurrent.futures
|
8 |
+
import multiprocessing # 添加multiprocessing模块以获取CPU核心数
|
9 |
|
10 |
# 添加当前目录和src目录到模块搜索路径
|
11 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
30 |
return {"status": "Exception", "error": "Input must be a list"}
|
31 |
|
32 |
results = []
|
33 |
+
# 获取CPU核心数作为最大线程数
|
34 |
+
max_workers = multiprocessing.cpu_count()
|
35 |
+
# 使用线程池并行处理多个测试用例,限制最大线程数为CPU核心数
|
36 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
|
37 |
# 提交所有任务到线程池
|
38 |
future_to_item = {executor.submit(evaluate_single_case, item): item for item in input_data}
|
39 |
# 获取结果
|