I have encountered error 'RuntimeError: dictionary changed size during iteration' while iterating through a dictionary in a thread,which is being inserted in another thread in Python 2.7.I found that by using Global Intrepreter Lock,we could lock a object in mutithreaded situation.
In thread1:
dictDemo[callid]=val
in thread2:
for key in dictDemo:
if key in dictDemo:
dictDemo.pop(key,None)
I encountered the error 'RuntimeError: dictionary changed size during iteration' in thread2 since thread1 works in the same time.**How can I use GIL to lock the dictDemo dictionary in thread2?**Or GIL can be used only for threads?Or is there a way to lock the dictionary so that to restrict the use of the object by 2 thread at a time?