Loading ccserver/utils.py +27 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ Some helpers used by cc-server. ''' from threading import Lock class Acquires(object): ''' Loading Loading @@ -34,3 +36,28 @@ class Acquires(object): def __exit__(self, exc_type, exc_value, traceback): for lock in self._locks: lock.release() class AcquiresAllOrNone(Acquires): ''' Class that extend Acquires to allow to release all lock if one of them is not free. ''' # Global acquire lock: acquirelock = Lock() def __enter__(self): while True: with self.acquirelock: acquired = [] for lock in self._locks: if not lock.acquire(False): for lock_acquired in acquired: lock_acquired.release() break else: acquired.append(lock) else: break Loading
ccserver/utils.py +27 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ Some helpers used by cc-server. ''' from threading import Lock class Acquires(object): ''' Loading Loading @@ -34,3 +36,28 @@ class Acquires(object): def __exit__(self, exc_type, exc_value, traceback): for lock in self._locks: lock.release() class AcquiresAllOrNone(Acquires): ''' Class that extend Acquires to allow to release all lock if one of them is not free. ''' # Global acquire lock: acquirelock = Lock() def __enter__(self): while True: with self.acquirelock: acquired = [] for lock in self._locks: if not lock.acquire(False): for lock_acquired in acquired: lock_acquired.release() break else: acquired.append(lock) else: break