@@ -392,7 +392,7 @@ def determine_best_candidate(
392392 try :
393393 candidate_index = 0
394394 original_len = len (candidates )
395- while True :
395+ while candidates :
396396 done = True if future_line_profile_results is None else future_line_profile_results .done ()
397397 if done and (future_line_profile_results is not None ):
398398 line_profile_results = future_line_profile_results .result ()
@@ -402,13 +402,7 @@ def determine_best_candidate(
402402 f"Added results from line profiler to candidates, total candidates now: { original_len } "
403403 )
404404 future_line_profile_results = None
405- try :
406- candidate = candidates .popleft ()
407- except IndexError :
408- if done :
409- break
410- time .sleep (0.1 )
411- continue
405+ candidate = candidates .popleft ()
412406 candidate_index += 1
413407 get_run_tmp_file (Path (f"test_return_values_{ candidate_index } .bin" )).unlink (missing_ok = True )
414408 get_run_tmp_file (Path (f"test_return_values_{ candidate_index } .sqlite" )).unlink (missing_ok = True )
@@ -517,8 +511,17 @@ def determine_best_candidate(
517511 self .write_code_and_helpers (
518512 self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
519513 )
520- if done and not candidates :
521- break
514+ if (not len (candidates )) and (
515+ not done
516+ ): # all original candidates processed but lp results haven't been processed
517+ concurrent .futures .wait ([future_line_profile_results ])
518+ line_profile_results = future_line_profile_results .result ()
519+ candidates .extend (line_profile_results )
520+ original_len += len (line_profile_results )
521+ logger .info (
522+ f"Added results from line profiler to candidates, total candidates now: { original_len } "
523+ )
524+ future_line_profile_results = None
522525 except KeyboardInterrupt as e :
523526 self .write_code_and_helpers (
524527 self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
0 commit comments