lsst.utils
14.0-6-g4f52afe+5
|
Public Member Functions | |
def | __init__ (self, lock=None) |
def | __enter__ (self) |
def | __exit__ (self, exc_type, exc_value, traceback) |
a class that assists in keeping methods thread-safe. This class is intended to be enlisted as a base class to the class being protected. A method that is to be protected from simultaneous access would include (at its beginning) a call to _checkLocked(): class MyClass(BaseClass, LockProtected): def __init__(self, lock=SharedLock): LockProtected.__init__(self, lock) ... def dangerous(self): self._checkLocked() ... Doing so will require that the protected class be "locked" before a protected method can be called or else an UnsafeAccessError will be raised. Locking is done via the with statement: mc = MyClass() with mc: mc.dangerous() For the locking to work, the protected class must provide to the LockProtected constructor a lock object. Typically this is a lsst.utils.multithreading.SharedLock instance or, if one wants to employ thread notification techniques, a lsst.utils.multithreading.SharedData instance. It should at least be a reentrant lock--that is, having the behavior of threading.RLock (from the standard Python Library). This class is primarily intended for protecting methods across multiple classes together via a single lock. That is, it can prevent simultaneous access to any protected method across multiple class instances. To accomplish this, each class to be protected should accept a lock as a constructor argument. Then the same lock is passed into all of the constructors that need protection together.
Definition at line 33 of file lockProtection.py.
def lsst.utils.multithreading.lockProtection.LockProtected.__init__ | ( | self, | |
lock = None |
|||
) |
initialize the lock protection @param lock a reentrant lock instance to use. If None, the protection behavior is disabled.
Definition at line 74 of file lockProtection.py.
def lsst.utils.multithreading.lockProtection.LockProtected.__enter__ | ( | self | ) |
Definition at line 83 of file lockProtection.py.
def lsst.utils.multithreading.lockProtection.LockProtected.__exit__ | ( | self, | |
exc_type, | |||
exc_value, | |||
traceback | |||
) |
Definition at line 87 of file lockProtection.py.