| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- Namespace List
- Namespace Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
locker Namespace Reference

## Classes
class | LockFile
| Lock a file. More...

## Functions
def | lock
def | unlock
def | _tmpFileName
def | _lckFileName
def | _linkCount
def | _read
def | _sleep

## Variables
| LOCK_EX fcntl.F_WRLCK
| LOCK_SH fcntl.F_RDLCK
| LOCK_NB fcntl.F_UNLCK

## Function Documentation

def locker._lckFileName | ( |  | fileName | ) |
| private

Definition at line 51 of file locker.py.

51
52 def _lckFileName(fileName):
53 return "%s.lock" % fileName

def locker._linkCount | ( |  | lockFileName | ) |
| private

Definition at line 54 of file locker.py.

54
55 def _linkCount( lockFileName ):
56 try:
57 return os.stat(lockFileName).st_nlink
58 except OSError, e:
59 if e.errno != errno.ENOENT:
60 raise
return -1

def locker._read | ( |  | fileName | ) |
| private

Definition at line 61 of file locker.py.

61
62 def _read(fileName):
63 try:
64 fp = open(fileName)
65 try: readFileName = fp.read()
66 finally: fp.close()
67 return readFileName
68 except EnvironmentError, e:
69 if e.errno != errno.ENOENT:
70 raise
71 return None

def locker._sleep | ( |  | ) |
| private

Definition at line 72 of file locker.py.

72
73 def _sleep(): time.sleep(8)

def locker._tmpFileName | ( |  | fileName | ) |
| private

Definition at line 49 of file locker.py.

49
50 def _tmpFileName(fileName):
return "%s.%s.%d" % ( fileName, socket.gethostname(), os.getpid() )

def locker.lock | ( |  | file | ) |

    Lock first 10 bytes of a file.

Definition at line 19 of file locker.py.

19
20 def lock(file):
21 """
22 Lock first 10 bytes of a file.
23 """
24 pos = file.tell() # remember current position
25 file.seek(0)
26 # By default, python tries about 10 times, then throws an exception.
27 # We want to wait forever.
28 acquired = False
29 while not acquired:
30 try:
31 msvcrt.locking(file.fileno(),msvcrt.LK_LOCK,10)
32 acquired = True
33 except IOError, x:
34 if x.errno != 36: # 36, AKA 'Resource deadlock avoided', is normal
35 raise
36 file.seek(pos) # reset position

def locker.unlock | ( |  | file | ) |

    Unlock first 10 bytes of a file.

Definition at line 37 of file locker.py.

37
38 def unlock(file):
39 """
40 Unlock first 10 bytes of a file.
41 """
42 pos = file.tell() # remember current position
43 file.seek(0)
44 msvcrt.locking(file.fileno(),msvcrt.LK_UNLCK,10)
45 file.seek(pos) # reset position

## Variable Documentation

locker.LOCK_EX fcntl.F_WRLCK

Definition at line 12 of file locker.py.

locker.LOCK_NB fcntl.F_UNLCK

Definition at line 14 of file locker.py.

locker.LOCK_SH fcntl.F_RDLCK

Definition at line 13 of file locker.py.