Add internal locking to bonobo.config.services.Exclusive.
This commit is contained in:
committed by
Romain Dorgueil
parent
0659263224
commit
448ae9ca8d
@ -146,14 +146,19 @@ class Exclusive(ContextDecorator):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_locks = {}
|
_locks = {}
|
||||||
|
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:
|
Exclusive.lock.acquire()
|
||||||
Exclusive._locks[_id] = threading.RLock()
|
try:
|
||||||
|
if not _id in Exclusive._locks:
|
||||||
|
Exclusive._locks[_id] = threading.RLock()
|
||||||
|
finally:
|
||||||
|
Exclusive.lock.release()
|
||||||
return Exclusive._locks[_id]
|
return Exclusive._locks[_id]
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user