Skip to content

Commit 75be8ee

Browse files
authored
Merge branch 'main' into remove-tiktoken
2 parents c5dbcbf + 3232228 commit 75be8ee

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

codeflash/optimization/function_optimizer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def determine_best_candidate(
393393
try:
394394
candidate_index = 0
395395
original_len = len(candidates)
396-
while candidates:
396+
while True:
397397
done = True if future_line_profile_results is None else future_line_profile_results.done()
398398
if done and (future_line_profile_results is not None):
399399
line_profile_results = future_line_profile_results.result()
@@ -403,8 +403,13 @@ def determine_best_candidate(
403403
f"Added results from line profiler to candidates, total candidates now: {original_len}"
404404
)
405405
future_line_profile_results = None
406+
try:
407+
candidate = candidates.popleft()
408+
except IndexError as e:
409+
if done:
410+
break
411+
continue
406412
candidate_index += 1
407-
candidate = candidates.popleft()
408413
get_run_tmp_file(Path(f"test_return_values_{candidate_index}.bin")).unlink(missing_ok=True)
409414
get_run_tmp_file(Path(f"test_return_values_{candidate_index}.sqlite")).unlink(missing_ok=True)
410415
logger.info(f"Optimization candidate {candidate_index}/{original_len}:")
@@ -512,7 +517,8 @@ def determine_best_candidate(
512517
self.write_code_and_helpers(
513518
self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path
514519
)
515-
520+
if done and not candidates:
521+
break
516522
except KeyboardInterrupt as e:
517523
self.write_code_and_helpers(
518524
self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path

0 commit comments

Comments
 (0)