|
6 | 6 | import threading |
7 | 7 | import time |
8 | 8 | from collections import Counter, defaultdict |
9 | | -from concurrent.futures import ProcessPoolExecutor, as_completed |
| 9 | +from concurrent.futures import ProcessPoolExecutor, as_completed, wait, ALL_COMPLETED |
10 | 10 | from datetime import datetime |
11 | 11 | from typing import Any, Dict, List, Tuple |
12 | 12 | from warnings import warn |
@@ -204,26 +204,14 @@ def evaluate(flags): |
204 | 204 | assert len(completion_id) == len(problems), "Missing problems in samples" |
205 | 205 |
|
206 | 206 | def stucking_checker(): |
207 | | - unchanged_duration = 0 |
208 | | - last_size = len(remainings) |
209 | | - |
210 | | - while remainings: |
211 | | - time.sleep(1) |
212 | | - current_size = len(remainings) |
213 | | - |
214 | | - if current_size != last_size or current_size == 0: |
215 | | - # Reset the unchanged duration if something has changed |
216 | | - unchanged_duration = 0 |
217 | | - last_size = current_size |
218 | | - else: |
219 | | - # Increment the duration if nothing has changed |
220 | | - unchanged_duration += 1 |
221 | | - |
222 | | - if unchanged_duration >= 240: |
| 207 | + not_done = [True] |
| 208 | + while len(not_done) > 0: |
| 209 | + done, not_done = wait(futures, timeout=240, return_when=ALL_COMPLETED) |
| 210 | + |
| 211 | + if len(done) == 0: |
223 | 212 | # Output warnings after 240 seconds of no change |
224 | 213 | warn("No samples have finished testing in the last 240s") |
225 | 214 | warn(f"{len(remainings)} samples to be tested: {remainings}") |
226 | | - unchanged_duration = 0 # Reset after warning |
227 | 215 |
|
228 | 216 | threading.Thread(target=stucking_checker).start() |
229 | 217 |
|
|
0 commit comments