朱东升 commited on
Commit
3402804
·
1 Parent(s): 6df6e43
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -32,7 +32,7 @@ task_history = []
32
  # Lock for shared resources
33
  lock = threading.Lock()
34
  # Number of worker threads
35
- worker_threads = multiprocessing.cpu_count()
36
  # Flag for running background threads
37
  running = True
38
  # Mapping from task type to processing time
@@ -144,7 +144,11 @@ def evaluate(input_data):
144
  return {"status": "Exception", "error": "Input must be a list"}
145
 
146
  results = []
147
- max_workers = multiprocessing.cpu_count()
 
 
 
 
148
  with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
149
  future_to_item = {executor.submit(evaluate_single_case, item): item for item in input_data}
150
  for future in concurrent.futures.as_completed(future_to_item):
@@ -173,13 +177,26 @@ def evaluate_single_case(input_data):
173
  if not completions:
174
  return {"status": "Exception", "error": "No code provided"}
175
 
 
 
 
176
  results = []
177
  for comp in completions:
178
  code = input_data.get('prompt') + comp + '\n' + input_data.get('tests')
179
- result = evaluate_code(code, language)
180
- if result["status"] == "OK":
181
- return result
182
- results.append(result)
 
 
 
 
 
 
 
 
 
 
183
 
184
  return results[0]
185
 
 
32
  # Lock for shared resources
33
  lock = threading.Lock()
34
  # Number of worker threads
35
+ worker_threads = max(1, multiprocessing.cpu_count() // 2) # Using half the available cores for better stability
36
  # Flag for running background threads
37
  running = True
38
  # Mapping from task type to processing time
 
144
  return {"status": "Exception", "error": "Input must be a list"}
145
 
146
  results = []
147
+
148
+ # Use a moderate number of workers for all language tests to ensure stability
149
+ # This prevents resource contention regardless of language
150
+ max_workers = max(1, min(multiprocessing.cpu_count() // 2, 4))
151
+
152
  with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
153
  future_to_item = {executor.submit(evaluate_single_case, item): item for item in input_data}
154
  for future in concurrent.futures.as_completed(future_to_item):
 
177
  if not completions:
178
  return {"status": "Exception", "error": "No code provided"}
179
 
180
+ # Use a retry mechanism for all languages for better reliability
181
+ max_retries = 2 # One retry for all languages
182
+
183
  results = []
184
  for comp in completions:
185
  code = input_data.get('prompt') + comp + '\n' + input_data.get('tests')
186
+
187
+ # Try up to max_retries + 1 times for all test cases
188
+ for attempt in range(max_retries + 1):
189
+ result = evaluate_code(code, language)
190
+
191
+ # If success or last attempt, return/record the result
192
+ if result["status"] == "OK" or attempt == max_retries:
193
+ if result["status"] == "OK":
194
+ return result
195
+ results.append(result)
196
+ break
197
+
198
+ # For retries, briefly wait to allow resources to stabilize
199
+ time.sleep(0.3)
200
 
201
  return results[0]
202