Use re-entrant lock.
While using django-prometheus I found a situation where adding a metric to the registry caused a read from cache. I had cache metrics enabled, which attempted to add cache metrics to the registry. This resulting in a deadlock as the second registry call attempted to obtain the lock already held lower on the call stack.
I changed usage to an RLock, which allows the lock to be obtained in a nested fashion within a call stack. This still provides thread safety.
@csmarchbanks Only one test needed to check the status of the lock. Therefore, I simply switched all locks to RLock and added a utility function (in the test file) for that test.
@csmarchbanks Thanks! I was not sure what to do and have not had a chance to research it.