Package pythonutils :: Module pathutils :: Class Lock
[hide private]
[frames] | no frames]

Class Lock
source code

object --+
         |
        Lock
Known Subclasses:
LockFile

A simple file lock, compatible with windows and Unixes.

Instance Methods [hide private]
  __init__(self, filename, timeout=5, step=0.1)
Create a Lock object on file filename
  lock(self, force=True)
Lock the file for access by creating a directory of the same name (plus a trailing underscore).
  unlock(self, ignore=True)
Release the lock.
  _mungedname(self)
Override this in a subclass if you want to change the way Lock creates the directory name.
  __del__(self)
Auto unlock when object is deleted.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__


Class Variables [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, filename, timeout=5, step=0.1)
(Constructor)

source code 

Create a Lock object on file filename

timeout is the time in seconds to wait before timing out, when attempting to acquire the lock.

step is the number of seconds to wait in between each attempt to acquire the lock.

Overrides: object.__init__

lock(self, force=True)

source code 

Lock the file for access by creating a directory of the same name (plus a trailing underscore).

The file is only locked if you use this class to acquire the lock before accessing.

If force is True (the default), then on timeout we forcibly acquire the lock.

If force is False, then on timeout a LockError is raised.

unlock(self, ignore=True)

source code 

Release the lock.

If ignore is True and removing the lock directory fails, then the error is surpressed. (This may happen if the lock was acquired via a timeout.)

_mungedname(self)

source code 
Override this in a subclass if you want to change the way Lock creates the directory name.

__del__(self)
(Destructor)

source code 
Auto unlock when object is deleted.