Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Thedict.update() modification check can be erroneously triggered by modifications todifferent dictionaries that happen toshare the underlying keys objects.
For example, in the following program, the creation and modification of thef2 object can lead to an incorrectRuntimeError raised in the main thread that operates on distinct dictionaries.
importtimeimportthreadingb=threading.Barrier(2)classFoo:passclassMyStr(str):def__hash__(self):returnsuper().__hash__()def__eq__(self,other):time.sleep(0.1)returnsuper().__eq__(other)defthread():b.wait()time.sleep(0.05)f2=Foo()f2.a="a"f2.b="b"f2.c="c"defmain():t1=threading.Thread(target=thread)t1.start()b.wait()f1=Foo()f1.a="a"f1.b="b"x= {}x[MyStr("a")]=MyStr("a")x.update(f1.__dict__)t1.join()if__name__=="__main__":main()
Traceback (most recent call last): File "/home/sgross/cpython/bad.py", line 44, in <module> main() ~~~~^^ File "/home/sgross/cpython/bad.py", line 39, in main x.update(f1.__dict__) ~~~~~~~~^^^^^^^^^^^^^RuntimeError: dict mutated during update