朱东升 commited on
Commit
b01f5f4
·
1 Parent(s): df91d37

requirements update26

Browse files
Files changed (1) hide show
  1. app.py +69 -1
app.py CHANGED
@@ -30,6 +30,12 @@ def evaluate(input_data):
30
  return {"status": "Exception", "error": "Input must be a list"}
31
 
32
  results = []
 
 
 
 
 
 
33
  max_workers = multiprocessing.cpu_count()
34
  with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
35
  future_to_item = {executor.submit(evaluate_single_case, item): item for item in input_data}
@@ -37,9 +43,72 @@ def evaluate(input_data):
37
  item = future_to_item[future]
38
  try:
39
  result = future.result()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  item.update(result)
41
  results.append(item)
42
  except Exception as e:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  item.update({"status": "Exception", "error": str(e)})
44
  results.append(item)
45
  return results
@@ -95,7 +164,6 @@ def evaluate_code(code, language):
95
  return result
96
 
97
  except Exception as e:
98
- print(1)
99
  return {"status": "Exception", "error": str(e)}
100
 
101
  # 创建Gradio接口
 
30
  return {"status": "Exception", "error": "Input must be a list"}
31
 
32
  results = []
33
+ # 定义系统错误关键词,用于判断是否需要重试
34
+ system_error_keywords = [
35
+ "resource", "timeout", "busy", "congestion", "memory",
36
+ "connection", "system", "overload", "refused", "reset"
37
+ ]
38
+
39
  max_workers = multiprocessing.cpu_count()
40
  with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
41
  future_to_item = {executor.submit(evaluate_single_case, item): item for item in input_data}
 
43
  item = future_to_item[future]
44
  try:
45
  result = future.result()
46
+
47
+ # 检查是否是系统错误,如果是,立即重试一次
48
+ if isinstance(result, dict) and result.get("status") == "Exception":
49
+ error_msg = str(result.get("error", "")).lower()
50
+
51
+ # 如果错误信息包含系统错误关键词,则重试
52
+ if any(keyword in error_msg for keyword in system_error_keywords):
53
+ print(f"检测到系统错误: {error_msg},正在重试...")
54
+ # 立即重试
55
+ retry_result = evaluate_single_case(item)
56
+ if isinstance(retry_result, dict) and retry_result.get("status") != "Exception":
57
+ # 重试成功,使用重试结果
58
+ result = retry_result
59
+ print(f"重试成功")
60
+ else:
61
+ print(f"重试失败")
62
+
63
+ # 检查结果列表
64
+ if isinstance(result, list):
65
+ for i, res in enumerate(result):
66
+ if isinstance(res, dict) and res.get("status") == "Exception":
67
+ error_msg = str(res.get("error", "")).lower()
68
+
69
+ # 如果错误信息包含系统错误关键词,则重试
70
+ if any(keyword in error_msg for keyword in system_error_keywords):
71
+ print(f"检测到列表中的系统错误: {error_msg},正在重试...")
72
+ # 仅重试这个失败的情况
73
+ code = item.get('prompt') + item.get('processed_completions', [])[i] + '\n' + item.get('tests')
74
+ retry_result = evaluate_code(code, item.get('language'))
75
+ if isinstance(retry_result, dict) and retry_result.get("status") != "Exception":
76
+ # 重试成功,更新结果
77
+ result[i] = retry_result
78
+ print(f"重试成功")
79
+ else:
80
+ print(f"重试失败")
81
+
82
+ # 如果是超时错误,也尝试重试一次
83
+ if isinstance(result, dict) and result.get("status") == "Timeout":
84
+ print(f"检测到超时错误,正在重试...")
85
+ # 立即重试
86
+ retry_result = evaluate_single_case(item)
87
+ if isinstance(retry_result, dict) and retry_result.get("status") != "Timeout":
88
+ # 重试成功,使用重试结果
89
+ result = retry_result
90
+ print(f"重试成功")
91
+ else:
92
+ print(f"重试失败")
93
+
94
  item.update(result)
95
  results.append(item)
96
  except Exception as e:
97
+ error_msg = str(e).lower()
98
+ # 检查是否是系统错误
99
+ if any(keyword in error_msg for keyword in system_error_keywords):
100
+ print(f"执行过程中检测到系统错误: {error_msg},正在重试...")
101
+ try:
102
+ # 立即重试
103
+ retry_result = evaluate_single_case(item)
104
+ item.update(retry_result)
105
+ results.append(item)
106
+ print(f"重试成功")
107
+ continue
108
+ except Exception as retry_e:
109
+ print(f"重试失败: {str(retry_e)}")
110
+
111
+ # 如果重试失败或不是系统错误,记录原始错误
112
  item.update({"status": "Exception", "error": str(e)})
113
  results.append(item)
114
  return results
 
164
  return result
165
 
166
  except Exception as e:
 
167
  return {"status": "Exception", "error": str(e)}
168
 
169
  # 创建Gradio接口