Skip to content

Commit 277c72a

Browse files
authored
fix: avoid triggering errors like "RuntimeError: dictionary changed s… (#1285)
* fix: avoid triggering errors like "RuntimeError: dictionary changed size during iteration" * style: reformat run_in_executor call for improved readability
1 parent 274e274 commit 277c72a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rdagent/utils/workflow/loop.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import asyncio
1212
import concurrent.futures
13+
import copy
1314
import os
1415
import pickle
1516
from collections import defaultdict
@@ -227,7 +228,11 @@ async def _run_step(self, li: int, force_subproc: bool = False) -> None:
227228
if force_subproc:
228229
curr_loop = asyncio.get_running_loop()
229230
with concurrent.futures.ProcessPoolExecutor() as pool:
230-
result = await curr_loop.run_in_executor(pool, func, self.loop_prev_out[li])
231+
# Using deepcopy is to avoid triggering errors like "RuntimeError: dictionary changed size during iteration"
232+
# GUESS: Some content in self.loop_prev_out[li] may be in the middle of being changed.
233+
result = await curr_loop.run_in_executor(
234+
pool, copy.deepcopy(func), copy.deepcopy(self.loop_prev_out[li])
235+
)
231236
else:
232237
# auto determine whether to run async or sync
233238
if asyncio.iscoroutinefunction(func):

0 commit comments

Comments
 (0)