Package grizzled :: Package io :: Module filelock :: Class FileLock
[frames] | no frames]

Class FileLock

object --+
         |
        FileLock

A FileLock object models a file lock. It wraps a file descriptor and contains methods to acquire and release a lock on the file.

File lock implementations that implement this interface are guaranteed to be advisory, but not mandatory, file locks. (They may, in fact, also be mandatory file locks, but they are not guaranteed to be.)

Currently, there are underlying implementations for both POSIX systems and Windows.

Instance Methods
 
__init__(self, fd)
Allocate a new file lock that operates on the specified file descriptor.
 
acquire(self, no_wait=False)
Lock the associated file.
 
release(self)
Unlock (i.e., release the lock on) the associated file.

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

Properties

Inherited from object: __class__

Method Details

__init__(self, fd)
(Constructor)

 
Allocate a new file lock that operates on the specified file descriptor.
Parameters:
  • fd (int) - Open file descriptor. The file must be opened for writing or updating, not reading.
Overrides: object.__init__

acquire(self, no_wait=False)

 
Lock the associated file. If someone already has the file locked, this method will suspend the calling process, unless no_wait is True.
Parameters:
  • no_wait (bool) - If False, then acquire() will suspend the calling process if someone has the file locked. If True, then acquire() will raise an IOError if the file is locked by someone else.
Raises:
  • IOError - If the file cannot be locked for any reason.