Problem with OrderedDict

Frank Millman frank at chagford.com
Wed May 30 10:32:29 EDT 2018


"Steven D'Aprano"  wrote in message news:pem8b8$lm6$4 at blaine.gmane.org...
>
> On Wed, 30 May 2018 10:48:06 +0200, Frank Millman wrote:
>
> > 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
>
>
> Can you share your simple example?
>

I can, but I actually found my error.

I habitually type -
    from collections import OrderedDict as OD
and
    from collections import defaultdict as DD

My fingers typed the second version by mistake (my brain had nothing to do 
with it!).

Now that I am using the correct version, I consistently get the 'OrderedDict 
mutated during iteration' message.

So working backwards, I have solved the first problem. I am no nearer to 
figuring out why it fails intermittently in my live program. The message 
from INADA Naoki suggests that it could be inherent in CPython, but I am not 
ready to accept that as an answer yet. I will keep plugging away and report 
back with any findings.

Frank





More information about the Python-list mailing list