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

Class FileLock

source code

object --+
         |
        FileLock

A file locking mechanism that has context-manager support so you can use it in a with statement. This should be relatively cross compatible as it doesn't rely on msvcrt or fcntl for the locking.

Instance Methods [hide private]
 
__init__(self, file_name, timeout=10, delay=0.05)
Prepare the file locker.
source code
 
acquire(self)
Acquire the lock, if possible.
source code
 
release(self)
Get rid of the lock by deleting the lockfile.
source code
 
__enter__(self)
Activated when used in the with statement.
source code
 
__exit__(self, type, value, traceback)
Activated at the end of the with statement.
source code
 
__del__(self)
Make sure that the FileLock instance doesn't leave a lockfile lying around.
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, file_name, timeout=10, delay=0.05)
(Constructor)

source code 

Prepare the file locker. Specify the file to lock and optionally the maximum timeout and the delay between each attempt to lock.

Overrides: object.__init__

acquire(self)

source code 

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(self)

source code 

Get rid of the lock by deleting the lockfile. When working in a `with` statement, this gets automatically called at the end.

__enter__(self)

source code 

Activated when used in the with statement. Should automatically acquire a lock to be used in the with block.

__exit__(self, type, value, traceback)

source code 

Activated at the end of the with statement. It automatically releases the lock if it isn't locked.