diff --git a/rdagent/utils/workflow/loop.py b/rdagent/utils/workflow/loop.py index 9fdaa529..34dc119e 100644 --- a/rdagent/utils/workflow/loop.py +++ b/rdagent/utils/workflow/loop.py @@ -10,6 +10,7 @@ Postscripts: import asyncio import concurrent.futures +import copy import os import pickle from collections import defaultdict @@ -227,7 +228,11 @@ class LoopBase: if force_subproc: curr_loop = asyncio.get_running_loop() with concurrent.futures.ProcessPoolExecutor() as pool: - result = await curr_loop.run_in_executor(pool, func, self.loop_prev_out[li]) + # Using deepcopy is to avoid triggering errors like "RuntimeError: dictionary changed size during iteration" + # GUESS: Some content in self.loop_prev_out[li] may be in the middle of being changed. + result = await curr_loop.run_in_executor( + pool, copy.deepcopy(func), copy.deepcopy(self.loop_prev_out[li]) + ) else: # auto determine whether to run async or sync if asyncio.iscoroutinefunction(func):