Hi I have a pretty complex kivy application. I was doing some stuff, I started the app but when I was trying to save the data, my app suddenly stopped without any error message: Process finished with exit code 1
After reflexion, I found out that I deleted a key on the dict I was iterating on !
So I should have seen RuntimeError: dictionary changed size during iteration
but nothing appeared ! Why and how to prevent this ?
(it can take al ong time to debug, I can't imagine without error message !).
Here is an example of a code that raise the needed error:
d = {"a":"e","b":"c"}
for k in d:
del d[k]
Since you did not provide any code, I can't give you a specific answer, but:
This error occurs very often when using a method such as
pop()
It happens, because you remove an item, while you are still iterating through your dictionary. If python now tries to access this very item, it can't and raises the error you mentioned.
This is easily solved by iterating over a copy of the dictionary and changing the values of the original while doing so.
This can be accomplished like this:
for i in original_dict.copy():
EDIT 1: To force python to show the error, you could do this:
try:
# your code
except Exception as e:
raise e