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

Class FileLock

source code

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 [hide private]
 
__init__(self, fd)
Allocate a new file lock that operates on the specified file descriptor.
source code
 
acquire(self, no_wait=False)
Lock the associated file.
source code
 
release(self)
Unlock (i.e., release the lock on) the associated file.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fd)
(Constructor)

source code 
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)

source code 
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.