500lines icon indicating copy to clipboard operation
500lines copied to clipboard

CI: Iterate through copy of dictionary that is modified during loop

Open Terr opened this issue 8 years ago • 1 comments

The CI dispatcher.py modifies the dict of dispatched commits while iterating through it using iteritems(). This can cause a RuntimeError (see https://docs.python.org/2.7/library/stdtypes.html#dict.iteritems)

This trivial example demonstrates the error:

d = {'a': 1, 'b': 2, 'c': 3}

for k, v in d.iteritems():
    del d[k]

Output:

Traceback (most recent call last):
  File "dict_modify.py", line 3, in <module>
    for k, v in d.iteritems():
RuntimeError: dictionary changed size during iteration

According to the Python docs there is a chance that it will run without error. But for me the error rate has been 100%.

Changing iteritems() to items() avoids the error.

Terr avatar Apr 22 '17 11:04 Terr

you are very good

haolipeng avatar Apr 26 '17 08:04 haolipeng