For Python 2, patching existing locks replaces RLock._RLock__owner with current thread ID no matter the old lock is locked or not and thus an unlocked RLock would have a non None owner (e.g. <_RLock owner=140106584489808 count=0>). Then if we acquire the RLock in the same thread, the method RLock.acquire would not invoke the _RLock__block.acquire() since it treats this is a recursive acquire by checking current thread ID. And then the following RLock.release would invoke the _RLock__block.release method resulting in the counter of Semaphore being improved to 2. There should be only two states being expected for RLock: 1. owner != None and count > 0 2. owner == None and count == 0 This patch fixs it by only setting locked RLocks' owner during patching.
16 KiB
16 KiB