Package ganeti :: Package utils :: Module filelock :: Class FileLock
[hide private]
[frames] | no frames]

Class FileLock

source code


Utility class for file locks.

Instance Methods [hide private]
 
__init__(self, fd, filename)
Constructor for FileLock.
source code
 
__del__(self) source code
 
Close(self)
Close the file and release the lock.
source code
 
_flock(self, flag, blocking, timeout, errmsg)
Wrapper for fcntl.flock.
source code
 
Exclusive(self, blocking=False, timeout=None)
Locks the file in exclusive mode.
source code
 
Shared(self, blocking=False, timeout=None)
Locks the file in shared mode.
source code
 
Unlock(self, blocking=True, timeout=None)
Unlocks the file.
source code

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

Class Methods [hide private]
 
Open(cls, filename)
Creates and opens a file to be used as a file-based lock.
source code
Static Methods [hide private]
 
_Lock(fd, flag, timeout) source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fd, filename)
(Constructor)

source code 

Constructor for FileLock.

Parameters:
  • fd (file) - File object
  • filename (str) - Path of the file opened at fd
Overrides: object.__init__

Open(cls, filename)
Class Method

source code 

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

Parameters:
  • filename (string) - path to the file to be locked

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

source code 

Wrapper for fcntl.flock.

Parameters:
  • flag (int) - operation flag
  • blocking (bool) - whether the operation should be done in blocking mode.
  • timeout (None or float) - for how long the operation should be retried (implies non-blocking mode).
  • errmsg (string) - error message in case operation fails.

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

source code 

Locks the file in exclusive mode.

Parameters:
  • blocking (boolean) - whether to block and wait until we can lock the file or return immediately
  • timeout (int or None) - if not None, the duration to wait for the lock (in blocking mode)

Shared(self, blocking=False, timeout=None)

source code 

Locks the file in shared mode.

Parameters:
  • blocking (boolean) - whether to block and wait until we can lock the file or return immediately
  • timeout (int or None) - if not None, the duration to wait for the lock (in blocking mode)

Unlock(self, blocking=True, timeout=None)

source code 

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 (boolean) - whether to block and wait until we can lock the file or return immediately
  • timeout (int or None) - if not None, the duration to wait for the lock (in blocking mode)