SU2
Public Member Functions | Public Attributes | List of all members
SU2.io.filelock.filelock Class Reference
Inheritance diagram for SU2.io.filelock.filelock:

Public Member Functions

def __init__ (self, file_name, timeout=10, delay=.05)
 
def acquire (self)
 
def release (self)
 
def __enter__ (self)
 
def __exit__ (self, type, value, traceback)
 
def __del__ (self)
 

Public Attributes

 is_locked
 
 lockfile
 
 file_name
 
 timeout
 
 delay
 
 fd
 

Detailed Description

A file locking mechanism that has context-manager support so 
    you can use it in a with statement. 
    
    Example:
    with filelock("test.txt", timeout=2, delay=0.5):
        print("Lock acquired.")
        # Do something with the locked file
        
    Inputs:
        file_name - filename to lock
        timeout   - default 10sec, maximum timeout to wait for lock
        delay     - default 0.05sec, delay between each attempt to lock
                    number incremented with a random perturbation
       
    original source: Evan Fosmark, BSD license
    http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/

Constructor & Destructor Documentation

§ __init__()

def SU2.io.filelock.filelock.__init__ (   self,
  file_name,
  timeout = 10,
  delay = .05 
)
Prepare the file locker. Specify the file to lock and optionally
    the maximum timeout and the delay between each attempt to lock.

§ __del__()

def SU2.io.filelock.filelock.__del__ (   self)
Make sure that the FileLock instance doesn't leave a lockfile
    lying around.

Member Function Documentation

§ __enter__()

def SU2.io.filelock.filelock.__enter__ (   self)
Activated when used in the with statement. 
    Should automatically acquire a lock to be used in the with block.

§ __exit__()

def SU2.io.filelock.filelock.__exit__ (   self,
  type,
  value,
  traceback 
)
Activated at the end of the with statement.
    It automatically releases the lock if it isn't locked.

§ acquire()

def SU2.io.filelock.filelock.acquire (   self)
Acquire the lock, if possible. If the lock is in use, it check again
    every `wait` seconds. It does this until it either gets the lock or
    exceeds `timeout` number of seconds, in which case it throws 
    an exception.

§ release()

def SU2.io.filelock.filelock.release (   self)
Get rid of the lock by deleting the lockfile. 
    When working in a `with` statement, this gets automatically 
    called at the end.

The documentation for this class was generated from the following file: