Problem with OrderedDict

Frank Millman frank at chagford.com
Wed May 30 04:48:06 EDT 2018


Hi all

I want to work backwards to solve this problem, so I have to explain it 
forwards to put you in the picture.

I have an Ordered Dictionary. Under certain circumstances I am getting this 
error -

    RuntimeError: OrderedDict mutated during iteration

I can see why this is happening, and I am pretty sure I can fix it by making 
a copy to iterate over.

However, the error seems to be intermittent - there are times when it should 
fail, but does not - so I want to investigate further.

I tried to reduce it to a simple example. I succeeded, but there are two 
problems -

1. It always fails, so I have not reproduced the intermittent nature yet.

2. It gives a different error -

    RuntimeError: dictionary changed size during iteration

So my first question is, what is the difference between the two error 
messages? I am using an OrderedDict for my test as well, so the difference 
is not caused by using a normal dictionary.

I am using Python 3.6.0.

Thanks

Frank Millman





More information about the Python-list mailing list