| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

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

    00051                               :
    00052         return "%s.lock" % fileName
    00053
        def _linkCount( lockFileName ):

def locker::_linkCount | ( |  | lockFileName | ) | `[private]`

Definition at line 54 of file locker.py.

    00054                                   :
    00055         try:
    00056             return os.stat(lockFileName).st_nlink
    00057         except OSError, e:
    00058             if e.errno != errno.ENOENT:
    00059                 raise
    00060             return -1
        def _read(fileName):

def locker::_read | ( |  | fileName | ) | `[private]`

Definition at line 61 of file locker.py.

    00061                        :
    00062         try:
    00063             fp = open(fileName)
    00064             try:     readFileName = fp.read()
    00065             finally: fp.close()
    00066             return readFileName
    00067         except EnvironmentError, e:
    00068             if e.errno != errno.ENOENT:
    00069                 raise
    00070             return None
    00071
        def _sleep(): time.sleep(8)

def locker::_sleep | ( |  | ) | `[private]`

Definition at line 72 of file locker.py.

    00072                 : time.sleep(8)
    00073

def locker::_tmpFileName | ( |  | fileName | ) | `[private]`

Definition at line 49 of file locker.py.

    00049                               :
    00050         return "%s.%s.%d" % ( fileName, socket.gethostname(), os.getpid() )
        def _lckFileName(fileName):

def locker::lock | ( |  | file | ) |

    Lock first 10 bytes of a file.

Definition at line 19 of file locker.py.

    00019                   :
    00020         """
    00021         Lock first 10 bytes of a file.
    00022         """
    00023         pos = file.tell() # remember current position
    00024         file.seek(0)
    00025         # By default, python tries about 10 times, then throws an exception.
    00026         # We want to wait forever.
    00027         acquired = False
    00028         while not acquired:
    00029             try:
    00030                 msvcrt.locking(file.fileno(),msvcrt.LK_LOCK,10)
    00031                 acquired = True
    00032             except IOError, x:
    00033                 if x.errno != 36: # 36, AKA 'Resource deadlock avoided', is normal
    00034                     raise
    00035         file.seek(pos) # reset position
    00036
        def unlock(file):

def locker::unlock | ( |  | file | ) |

    Unlock first 10 bytes of a file.

Definition at line 37 of file locker.py.

    00037                     :
    00038         """
    00039         Unlock first 10 bytes of a file.
    00040         """
    00041         pos = file.tell() # remember current position
    00042         file.seek(0)
    00043         msvcrt.locking(file.fileno(),msvcrt.LK_UNLCK,10)
    00044         file.seek(pos) # reset position
    00045
    elif os.name =='posix':

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