Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: dictionary changed size during iteration #669

Open
bradmonk opened this issue Sep 21, 2018 · 0 comments
Open

RuntimeError: dictionary changed size during iteration #669

bradmonk opened this issue Sep 21, 2018 · 0 comments

Comments

@bradmonk
Copy link

>>> %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):
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

No branches or pull requests

1 participant