| The Gaudi Framework v27r1

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

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

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__ (self)
def | __enter__ (self)
def | __exit__ (self, type, value, traceback)

## 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 63 of file locker.py.

## Constructor & Destructor Documentation

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

Definition at line 64 of file locker.py.

64 def __init__(self, name, temporary = False):
65 self.name = name
66 self.temporary = temporary
67 self.file = None
68 self.log = logging.getLogger("LockFile")
69 self.log.info("%s - Locking on %s", time.strftime("%Y-%m-%d_%H:%M:%S"), self.name)
70 if not os.path.exists(name):
71 mode = "w"
72 else:
73 self.temporary = False # I do not want to delete a file I didn't create
74 mode = "r+"
75 try:
76 self.file = open(self.name, mode)
77 lock(self.file)
78 except:
79 self.log.warning("Cannot acquire lock on %s", self.name)
80
locker.LockFile.file
file
Definition: locker.py:67
locker.LockFile.name
name
Definition: locker.py:65
locker.lock
def lock(file)
Definition: locker.py:16
locker.LockFile.__init__
def __init__
Definition: locker.py:64
locker.LockFile.temporary
temporary
Definition: locker.py:66
locker.LockFile.log
log
Definition: locker.py:68

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

Definition at line 81 of file locker.py.

81 def __del__(self):
82 if self.file:
83 unlock(self.file)
84 self.file.close()
85 if self.temporary:
86 try:
87 os.remove(self.name)
88 except:
89 pass
90 self.log.info("%s - Lock on %s released", time.strftime("%Y-%m-%d_%H:%M:%S"), self.name)
91 self.file = None # Don't unlock twice!
92
93
locker.LockFile.file
file
Definition: locker.py:67
locker.LockFile.name
name
Definition: locker.py:65
locker.LockFile.temporary
temporary
Definition: locker.py:66
locker.LockFile.__del__
def __del__(self)
Definition: locker.py:81
locker.unlock
def unlock(file)
Definition: locker.py:34

## Member Function Documentation

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

Definition at line 96 of file locker.py.

96 def __enter__(self):
97 return self
98
locker.LockFile.__enter__
def __enter__(self)
Definition: locker.py:96

def locker.LockFile.__exit__ | ( |  | self,
|  |  | type,
|  |  | value,
|  |  | traceback
| ) |  |

Definition at line 99 of file locker.py.

99 def __exit__(self, type, value, traceback):
100 self.__del__()
101
102
locker.LockFile.__exit__
def __exit__(self, type, value, traceback)
Definition: locker.py:99
locker.LockFile.__del__
def __del__(self)
Definition: locker.py:81

## Member Data Documentation

locker.LockFile.file

Definition at line 67 of file locker.py.

locker.LockFile.log

Definition at line 68 of file locker.py.

locker.LockFile.name

Definition at line 65 of file locker.py.

locker.LockFile.temporary

Definition at line 66 of file locker.py.

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

- GaudiPolicy/scripts/locker.py