500lines
500lines copied to clipboard
CI: Iterate through copy of dictionary that is modified during loop
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.
you are very good