Skip to content
This repository was archived by the owner on Mar 22, 2026. It is now read-only.
This repository was archived by the owner on Mar 22, 2026. It is now read-only.

RuntimeError: dictionary changed size during iteration #669

Description

@bradmonk
>>> %tb
RuntimeError: dictionary changed size during iteration
....
<ipython-input-1-12c676190a3c> in __rodeo_get_variables(session)
     29 
     30     SPECIAL_VARS = ["In", "Out"]
---> 31     for variable_name in session.keys():
     32 
     33         if variable_name.startswith("_") or variable_name in SPECIAL_VARS:
RuntimeError: dictionary changed size during iteration

for variable_name in session.keys():

In Python 2.x calling keys makes a copy of the key that you can iterate over while modifying the dict:

for variable_name in session.keys():

This doesn't work in Python 3.x because keys returns an iterator instead of a list. Apparently the work-around for Python 3.x is to use list() to force a copy of the keys to be made:

for variable_name in list(session):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions