Merge branch 'exclusive-locks' of https://github.com/kasei/bonobo into kasei-exclusive-locks

This commit is contained in:
Romain Dorgueil
2019-05-16 09:58:37 +01:00

View File

@ -146,14 +146,16 @@ class Exclusive(ContextDecorator):
""" """
_locks = {} _locks = {}
_locks_creation_lock = threading.Lock()
def __init__(self, wrapped): def __init__(self, wrapped):
self._wrapped = wrapped self._wrapped = wrapped
def get_lock(self): def get_lock(self):
_id = id(self._wrapped) _id = id(self._wrapped)
if not _id in Exclusive._locks: with Exclusive._locks_creation_lock:
Exclusive._locks[_id] = threading.RLock() if not _id in Exclusive._locks:
Exclusive._locks[_id] = threading.RLock()
return Exclusive._locks[_id] return Exclusive._locks[_id]
def __enter__(self): def __enter__(self):