Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/easyscience/global_object/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,23 @@ def __init__(self):

def vertices(self) -> List[str]:
"""returns the vertices of a map"""
return list(self._store.keys())
# Create a copy to avoid "dictionary changed size during iteration" errors
# This can happen when objects are garbage collected during iteration
try:
return list(self._store.keys())
except RuntimeError:
# If we hit a concurrent modification, create a safe copy
# by iterating through items and collecting valid keys
valid_keys = []
# Query all weak references to avoid modification during iteration
# WeakValueDictionary does not support items() directly, so we access the underlying data
items = list(self._store.data.items())
for key, ref in items:
# Instantiating the weak reference to see if the object is still alive
# This test does not modify the dictionary
if ref() is not None:
valid_keys.append(key)
return valid_keys

def edges(self):
"""returns the edges of a map"""
Expand Down
Loading