class documentation

class FileLock(object):

View In Hierarchy

Utility class for file locks.

Class Method Open Creates and opens a file to be used as a file-based lock.
Method __del__ Undocumented
Method __init__ Constructor for FileLock.
Method Close Close the file and release the lock.
Method Exclusive Locks the file in exclusive mode.
Method Shared Locks the file in shared mode.
Method Unlock Unlocks the file.
Instance Variable fd Undocumented
Instance Variable filename Undocumented
Static Method _Lock Undocumented
Method _flock Wrapper for fcntl.flock.
@classmethod
def Open(cls, filename):

Creates and opens a file to be used as a file-based lock.

Parameters
filename:stringpath to the file to be locked
def __del__(self):

Undocumented

def __init__(self, fd, filename):

Constructor for FileLock.

Parameters
fd:fileFile object
filename:strPath of the file opened at fd
def Close(self):

Close the file and release the lock.

def Exclusive(self, blocking=False, timeout=None):

Locks the file in exclusive mode.

Parameters
blocking:booleanwhether to block and wait until we can lock the file or return immediately
timeout:int or Noneif not None, the duration to wait for the lock (in blocking mode)
def Shared(self, blocking=False, timeout=None):

Locks the file in shared mode.

Parameters
blocking:booleanwhether to block and wait until we can lock the file or return immediately
timeout:int or Noneif not None, the duration to wait for the lock (in blocking mode)
def Unlock(self, blocking=True, timeout=None):

Unlocks the file.

According to flock(2), unlocking can also be a nonblocking operation:

  To make a non-blocking request, include LOCK_NB with any of the above
  operations.
Parameters
blocking:booleanwhether to block and wait until we can lock the file or return immediately
timeout:int or Noneif not None, the duration to wait for the lock (in blocking mode)
fd =

Undocumented

filename =

Undocumented

@staticmethod
def _Lock(fd, flag, timeout):

Undocumented

def _flock(self, flag, blocking, timeout, errmsg):

Wrapper for fcntl.flock.

Parameters
flag:intoperation flag
blocking:boolwhether the operation should be done in blocking mode.
timeout:None or floatfor how long the operation should be retried (implies non-blocking mode).
errmsg:stringerror message in case operation fails.