HWRF  trunk@4391
Public Member Functions | List of all members
produtil.locking.LockFile Class Reference

Automates locking of a lockfile. More...

Detailed Description

Automates locking of a lockfile.

1 with LockFile("/path/to/lock.file"):
2  ... do things while file is locked ...
3 ...file is no longer locked.

Definition at line 66 of file locking.py.

Inheritance diagram for produtil.locking.LockFile:

Public Member Functions

def __hash__ (self)
 Return a hash of this object. More...
 
def __eq__ (self, other)
 Is this lock the same as that lock?
 
def __init__
 Creates an object that will lock the specified file. More...
 
def acquire_impl (self)
 Internal implementation function; do not call directly. More...
 
def release_impl (self)
 Internal implementation function; do not call directly. More...
 
def acquire (self)
 Acquire the lock. More...
 
def release (self)
 Release the lock. More...
 
def __enter__ (self)
 Calls self.acquire() to acquire the lock. More...
 
def __exit__ (self, etype, evalue, etraceback)
 Calls self.release() to release the lock. More...
 

Constructor & Destructor Documentation

def produtil.locking.LockFile.__init__ (   self,
  filename,
  until = None,
  logger = None,
  max_tries = 10,
  sleep_time = 3,
  first_warn = 0,
  giveup_quiet = False 
)

Creates an object that will lock the specified file.

Parameters
filenamethe file to lock
untilUnused.
loggerOptional: a logging.Logger to log messages
max_triesOptional: maximum tries before giving up on locking
sleep_timeOptional: approximate sleep time between locking attempts.
first_warnOptional: first locking failure at which to write warnings to the logger
giveup_quietOptional: if True, do not log the final failure to lock

Definition at line 80 of file locking.py.

Member Function Documentation

def produtil.locking.LockFile.__enter__ (   self)

Calls self.acquire() to acquire the lock.

Definition at line 149 of file locking.py.

def produtil.locking.LockFile.__exit__ (   self,
  etype,
  evalue,
  etraceback 
)

Calls self.release() to release the lock.

Parameters
etype,evalue,etracebackException information.

Definition at line 153 of file locking.py.

def produtil.locking.LockFile.__hash__ (   self)

Return a hash of this object.

Definition at line 74 of file locking.py.

def produtil.locking.LockFile.acquire (   self)

Acquire the lock.

Will try for a while, and will raise LockHeld when giving up.

Definition at line 131 of file locking.py.

Referenced by produtil.locking.LockFile.__enter__().

def produtil.locking.LockFile.acquire_impl (   self)

Internal implementation function; do not call directly.

Does the actual work of acquiring the lock, without retries, logging or sleeping. Will raise LockHeld if it cannot acquire the lock.

Definition at line 103 of file locking.py.

Referenced by produtil.locking.LockFile.acquire().

def produtil.locking.LockFile.release (   self)

Release the lock.

May raise exceptions on unexpected failures.

Definition at line 138 of file locking.py.

Referenced by produtil.locking.LockFile.__exit__().

def produtil.locking.LockFile.release_impl (   self)

Internal implementation function; do not call directly.

Does the actual work of releasing the lock, without retries, logging or sleeping.

Definition at line 123 of file locking.py.

Referenced by produtil.locking.LockFile.release().


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