it gives me this error:
Exception in thread Thread-163:
Traceback (most recent call last):
File "C:\Python26\lib\threading.py", line 532, in __bootstrap_inner
self.run()
File "C:\Python26\lib\threading.py", line 736, in run
self.function(*self.args, **self.kwargs)
File "C:\Users\Public\SoundLog\Code\Código Python\SoundLog\SoundLog.py", line 337, in getInfo
self.data1 = copy.deepcopy(Auxiliar.DataCollection.getInfo(1))
File "C:\Python26\lib\copy.py", line 162, in deepcopy
y = copier(x, memo)
File "C:\Python26\lib\copy.py", line 254, in _deepcopy_dict
for key, value in x.iteritems():
RuntimeError: dictionary changed size during iteration
while executing my python program.
How can I avoid this to happen?
Thanks in advance 😉
The normal advice, as per the other answers, would be to avoid using
iteritems(useitemsinstead). That of course is not an option in your case, since theiteritemscall is being done on your behalf deep in the bowels of a system call.Therefore, what I would suggest, assuming
Auxiliar.DataCollection.getInfo(1)returns a dictionary (which is the one that’s changing during the copy) is that you change yourdeepcopycall to:This takes a “snapshot” of the dict in question, and the snapshot won’t change, so you’ll be fine.
If
Auxiliar.DataCollection.getInfo(1)does not return a dict, but some more complicated object which includes dicts as items and/or attributes, it will be a bit more complicated, since those dicts are what you’ll need to snapshot. However, it’s impossible to be any more specific in this case, since you give us absolutely no clue as to the code that composes that crucialAuxiliar.DataCollection.getInfo(1)call!-)