mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-27 15:37:44 +00:00
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
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user