Package dogtail :: Module utils :: Class Lock
[hide private]
[frames] | no frames]

Class Lock

source code

object --+
         |
        Lock

A mutex implementation that uses atomicity of the mkdir operation in UNIX-like systems. This can be used by scripts to provide for mutual exlusion, either in single scripts using threads etc. or i.e. to handle sitations of possible collisions among multiple running scripts. You can choose to make randomized single-script wise locks or a more general locks if you do not choose to randomize the lockdir name

Instance Methods [hide private]
 
__init__(self, location='/tmp', lockname='dogtail_lockdir_', randomize=True)
You can change the default lockdir location or name.
source code
 
lock(self)
Creates a lockdir based on the settings on Lock() instance creation.
source code
 
unlock(self)
Removes a lock.
source code
 
__del__(self)
Makes sure lock is removed when the process ends.
source code
 
__getPostfix(self) 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, location='/tmp', lockname='dogtail_lockdir_', randomize=True)
(Constructor)

source code 

You can change the default lockdir location or name. Setting randomize to False will result in no random string being appened to the lockdir name.

Overrides: object.__init__

lock(self)

source code 

Creates a lockdir based on the settings on Lock() instance creation. Raises OSError exception of the lock is already present. Should be atomic on POSIX compliant systems.

unlock(self)

source code 

Removes a lock. Will raise OSError exception if the lock was not present. Should be atomic on POSIX compliant systems.

__del__(self)
(Destructor)

source code 

Makes sure lock is removed when the process ends. Although not when killed indeed.