| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
locker.LockFile Class Reference

Lock a file. More...

Inheritance diagram for locker.LockFile:
[legend]
Collaboration diagram for locker.LockFile:
[legend]

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

## Constructor & Destructor Documentation

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

Definition at line 132 of file locker.py.

132
133 def __init__(self, name, temporary = False):
134 self.name = name
135 self.temporary = temporary
136 self.file = None
137 self.log = logging.getLogger("LockFile")
138 self.log.info("%s - Locking on %s", time.strftime("%Y-%m-%d_%H:%M:%S"), self.name)
139 if not os.path.exists(name):
140 mode = "w"
141 else:
142 self.temporary = False # I do not want to delete a file I didn't create
143 mode = "r+"
144 try:
145 self.file = open(self.name, mode)
146 lock(self.file)
147 except:
self.log.warning("Cannot acquire lock on %s", self.name)

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

Definition at line 148 of file locker.py.

148
149 def __del__(self):
150 if self.file:
151 unlock(self.file)
152 self.file.close()
153 if self.temporary:
154 try:
155 os.remove(self.name)
156 except:
157 pass
158 self.log.info("%s - Lock on %s released", time.strftime("%Y-%m-%d_%H:%M:%S"), self.name)
159

## 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_v25r0/GaudiPolicy/scripts/locker.py