| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# locker::LockFile Class Reference

List of all members.

## Detailed Description

Lock a file.

The file for the lock is created if it doesn't exists and it the "temporary" argument is set to True it will also be deleted when the lock is not needed. The unlocking is done in the destructor (RAII pattern).

Definition at line 131 of file locker.py.

## Public Member Functions
def | __init__
def | __del__
## Public Attributes
| name
| temporary
| file
| log

## Member Function Documentation

def locker::LockFile::__init__ | ( |  | self,
|  |  | name,
|  |  | temporary = `False` |
| ) |  |  |

Definition at line 132 of file locker.py.

    00132                                                :
    00133         self.name = name
    00134         self.temporary = temporary
    00135         self.file = None
    00136         self.log = logging.getLogger("LockFile")
    00137         self.log.info("%s - Locking on %s", time.strftime("%Y-%m-%d_%H:%M:%S"), self.name)
    00138         if not os.path.exists(name):
    00139             mode = "w"
    00140         else:
    00141             self.temporary = False # I do not want to delete a file I didn't create
    00142             mode = "r+"
    00143         try:
    00144             self.file = open(self.name, mode)
    00145             lock(self.file)
    00146         except:
    00147             self.log.warning("Cannot acquire lock on %s", self.name)
        def __del__(self):

def locker::LockFile::__del__ | ( |  | self | ) |

Definition at line 148 of file locker.py.

    00148                      :
    00149         if self.file:
    00150             unlock(self.file)
    00151             self.file.close()
    00152             if self.temporary:
    00153                 try:
    00154                     os.remove(self.name)
    00155                 except:
    00156                     pass
    00157             self.log.info("%s - Lock on %s released", time.strftime("%Y-%m-%d_%H:%M:%S"), self.name)
    00158

## Member Data Documentation

locker::LockFile::name

Definition at line 133 of file locker.py.

locker::LockFile::temporary

Definition at line 134 of file locker.py.

locker::LockFile::file

Definition at line 135 of file locker.py.

locker::LockFile::log

Definition at line 136 of file locker.py.

The documentation for this class was generated from the following file:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r6/GaudiPolicy/scripts/locker.py