@@ -392,7 +392,7 @@ def determine_best_candidate(
392392 try :
393393 candidate_index = 0
394394 original_len = len (candidates )
395- while candidates :
395+ while True :
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,8 +402,13 @@ 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 as e :
408+ if done :
409+ break
410+ continue
405411 candidate_index += 1
406- candidate = candidates .popleft ()
407412 get_run_tmp_file (Path (f"test_return_values_{ candidate_index } .bin" )).unlink (missing_ok = True )
408413 get_run_tmp_file (Path (f"test_return_values_{ candidate_index } .sqlite" )).unlink (missing_ok = True )
409414 logger .info (f"Optimization candidate { candidate_index } /{ original_len } :" )
@@ -511,7 +516,8 @@ def determine_best_candidate(
511516 self .write_code_and_helpers (
512517 self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
513518 )
514-
519+ if done and not candidates :
520+ break
515521 except KeyboardInterrupt as e :
516522 self .write_code_and_helpers (
517523 self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
0 commit comments