Uranium
Application Framework
Loading...
Searching...
No Matches
UM.LockFile.LockFile Class Reference

Manage a lock file for reading / writing in a directory. More...

Public Member Functions

 __init__ (self, str filename, int timeout=10, str wait_msg="Waiting for lock file to disappear...")
 Creates the locker instance that will hold the lock file.
 
 __enter__ (self)
 Attempt to grab the lock file for personal use.
 
 __exit__ (self, exc_type, exc_val, exc_tb)
 Release the lock file so that other processes may use it.
 

Protected Member Functions

 _waitLockFileDisappear (self)
 Block the thread until the lock file no longer exists.
 
 _createLockFile (self)
 Creates the lock file on the file system.
 
 _deleteLockFile (self)
 Deletes the lock file from the file system.
 

Protected Attributes

 _filename
 
 _wait_msg
 
 _timeout
 

Detailed Description

Manage a lock file for reading / writing in a directory.

Parameters
filenamethe filename to use as lock file
timeoutin seconds; if the file is too old by this amount, then it gets ignored
wait_msgthe message to log when waiting for the lock file to disappear

example usage: $ with LockFile("my_lock_file.lock"): $ <do something in a directory>

Constructor & Destructor Documentation

◆ __init__()

UM.LockFile.LockFile.__init__ (   self,
str  filename,
int   timeout = 10,
str   wait_msg = "Waiting for lock file to disappear..." 
)

Creates the locker instance that will hold the lock file.

Parameters
filenameThe name and path of the lockfile to create.
timeoutAfter this amount of seconds, the lock will break regardless of the state of the file system.
wait_msgA message to log when the thread is blocked by the lock. It is intended that you modify this to better indicate what lock file is blocking the thread.

Member Function Documentation

◆ __exit__()

UM.LockFile.LockFile.__exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)

Release the lock file so that other processes may use it.

Parameters
exc_typeThe type of exception that was raised during the with block, if any. Use None if no exception was raised.
exc_valThe exception instance that was raised during the with block, if any. Use None if no exception was raised.
exc_tbThe traceback frames at the time the exception occurred, if any. Use None if no exception was raised.

◆ _createLockFile()

UM.LockFile.LockFile._createLockFile (   self)
protected

Creates the lock file on the file system.

The lock file is filled with the current process ID. Python's own GIL will ensure that this is thread-safe then.

◆ _waitLockFileDisappear()

UM.LockFile.LockFile._waitLockFileDisappear (   self)
protected

Block the thread until the lock file no longer exists.

This is implemented using a spin loop.


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