Skip to content

Switching ThreadSafeAttributes code to use a threading.RLock

Compare
Choose a tag to compare
@aleph2c aleph2c released this 23 Sep 13:22
· 71 commits to master since this release

The previous, v4.1.3, version of miros ThreadSafeAttributes class would not protect thread-safe-attributes from race conditions when they were used with the non-atomic "+=", "-=" ... "<<=" family of operations. (I could not get the broken code to fail in my tests, it was a review that brought the error to my attention; thank you to Ljubomir Kaludjercic for pointing this out to me).

To fix this issue, the deque was removed and a threading.Rlock was used with the inspect module, within a descriptor. Upon access, the descriptor checks to see if the previous line of code contains a "+=", "-=", ... "<<=" and if so it will leave the lock active until the value is set, see the code here. The usage of this limited protection was explained and documented in the example section of miros.ca, you can see it here.