From b63b79f26f29b21d30f0f2b40f1787cdc212a58c Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 17 Jun 2025 15:46:38 +0800 Subject: [PATCH] chore: break when loop_n runs out (#964) * raise loop termination in execute_loop * add SENTINEL --- rdagent/utils/workflow/loop.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rdagent/utils/workflow/loop.py b/rdagent/utils/workflow/loop.py index 6859e70a..92271be0 100644 --- a/rdagent/utils/workflow/loop.py +++ b/rdagent/utils/workflow/loop.py @@ -96,6 +96,7 @@ class LoopBase: ] = () # you can define a list of error that will withdraw current loop EXCEPTION_KEY = "_EXCEPTION" + SENTINEL = -1 _pbar: tqdm # progress bar instance @@ -261,6 +262,8 @@ class LoopBase: # exit on loop limitation if self.loop_n is not None: if self.loop_n <= 0: + for _ in range(RD_AGENT_SETTINGS.get_max_parallel()): + self.queue.put_nowait(self.SENTINEL) break self.loop_n -= 1 @@ -278,6 +281,8 @@ class LoopBase: while True: # 1) get the tasks to goon loop `li` li = await self.queue.get() + if li == self.SENTINEL: + break # 2) run the unfinished steps while self.step_idx[li] < len(self.steps): if self.step_idx[li] == len(self.steps) - 1: