| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

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.

    00052                               :
    00053         return "%s.lock" % fileName

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

Definition at line 54 of file locker.py.

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

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

Definition at line 61 of file locker.py.

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

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.

    00050                               :
            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.

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

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

    Unlock first 10 bytes of a file.

Definition at line 37 of file locker.py.

    00038                     :
    00039         """
    00040         Unlock first 10 bytes of a file.
    00041         """
    00042         pos = file.tell() # remember current position
    00043         file.seek(0)
    00044         msvcrt.locking(file.fileno(),msvcrt.LK_UNLCK,10)
    00045         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.

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