@@ -392,8 +392,7 @@ def determine_best_candidate(
392392 try :
393393 candidate_index = 0
394394 original_len = len (candidates )
395- # TODO replace while true with something safer, we dont want accidental infinite loops
396- while True :
395+ while candidates :
397396 done = True if future_line_profile_results is None else future_line_profile_results .done ()
398397 if done and (future_line_profile_results is not None ):
399398 line_profile_results = future_line_profile_results .result ()
@@ -403,13 +402,7 @@ def determine_best_candidate(
403402 f"Added results from line profiler to candidates, total candidates now: { original_len } "
404403 )
405404 future_line_profile_results = None
406- try :
407- candidate = candidates .popleft ()
408- except IndexError :
409- if done :
410- break
411- time .sleep (0.1 )
412- continue
405+ candidate = candidates .popleft ()
413406 candidate_index += 1
414407 get_run_tmp_file (Path (f"test_return_values_{ candidate_index } .bin" )).unlink (missing_ok = True )
415408 get_run_tmp_file (Path (f"test_return_values_{ candidate_index } .sqlite" )).unlink (missing_ok = True )
@@ -518,8 +511,15 @@ def determine_best_candidate(
518511 self .write_code_and_helpers (
519512 self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
520513 )
521- if done and not candidates :
522- break
514+ if (not len (candidates )) and (not done ): # all original candidates processed but lp results haven't been processed
515+ concurrent .futures .wait ([future_line_profile_results ])
516+ line_profile_results = future_line_profile_results .result ()
517+ candidates .extend (line_profile_results )
518+ original_len += len (line_profile_results )
519+ logger .info (
520+ f"Added results from line profiler to candidates, total candidates now: { original_len } "
521+ )
522+ future_line_profile_results = None
523523 except KeyboardInterrupt as e :
524524 self .write_code_and_helpers (
525525 self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
0 commit comments