| # Gaudi Framework, version v22r0 |

Home |  | Generated: 9 Feb 2011

# locker::LockFile Class Reference

Lock a file. More...

List of all members.

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

## 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.

## Member Function Documentation

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

Definition at line 148 of file locker.py.

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

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

Definition at line 132 of file locker.py.

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

## Member Data Documentation

locker::LockFile::file

Definition at line 135 of file locker.py.

locker::LockFile::log

Definition at line 136 of file locker.py.

locker::LockFile::name

Definition at line 133 of file locker.py.

locker::LockFile::temporary

Definition at line 134 of file locker.py.

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines