Skip to content

fix: wrap _turn_end_hooks iteration with list() to prevent RuntimeError#486

Merged
lsdefine merged 1 commit into
lsdefine:mainfrom
w286554018:fix/dict-iteration-runtime-error
May 26, 2026
Merged

fix: wrap _turn_end_hooks iteration with list() to prevent RuntimeError#486
lsdefine merged 1 commit into
lsdefine:mainfrom
w286554018:fix/dict-iteration-runtime-error

Conversation

@w286554018
Copy link
Copy Markdown
Contributor

When a hook modifies _turn_end_hooks dict during iteration in turn_end_callback, Python raises RuntimeError: dictionary changed size during iteration.

This fix wraps the .values() call with list() to create a snapshot of the hooks before iterating, preventing the RuntimeError.

Changes:

  • ga.py line 576: for hook in getattr(self.parent, '_turn_end_hooks', {}).values()for hook in list(getattr(self.parent, '_turn_end_hooks', {}).values())

When a hook modifies _turn_end_hooks dict during iteration in
turn_end_callback, Python raises RuntimeError: dictionary changed
size during iteration. Wrapping .values() with list() creates a
snapshot copy, preventing this error.
Copy link
Copy Markdown
Owner

@lsdefine lsdefine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: small safe fix to snapshot hook values during iteration.

@lsdefine lsdefine merged commit 54bc23a into lsdefine:main May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants