Author vstinner
Recipients brett.cannon, ncoghlan, serhiy.storchaka, vstinner
Date 2017-08-08.23:40:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1502235656.48.0.208405535066.issue31070@psf.upfronthosting.co.za>
In-reply-to
Content
The problem is the weakref callback of _module_locks. It seems like the callback is called after a second thread replaced _module_locks[name]

* Thread 1: _get_module_lock('random') sets _module_locks['random'] and registers a weakref callback on the newly created lock

* Thread 1: the lock is destroyed, the weakref callback will be called as soon as possible

* Thread 2: _get_module_lock('random') sees that the weakref is dead and so replaces _module_locks['random'] with a new lock, and registers a new weakref callback on the second lock

* Thread 1: Call the weakref callback removing _module_locks['random'] -- BUG: the callback is called too late, after Thread 2 already sets a new lock

* Thread 2: The lock is destroyed, the second weakref callback will be called as soon as possible

* Thread 2: The second callback is called and fails with KeyError since _module_locks['random'] was already called in the Thread 1 in the meanwhile
History
Date User Action Args
2017-08-08 23:40:56vstinnersetrecipients: + vstinner, brett.cannon, ncoghlan, serhiy.storchaka
2017-08-08 23:40:56vstinnersetmessageid: <1502235656.48.0.208405535066.issue31070@psf.upfronthosting.co.za>
2017-08-08 23:40:56vstinnerlinkissue31070 messages
2017-08-08 23:40:56vstinnercreate