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

Public Member Functions

None __init__ (self, str filename, int timeout=10, str wait_msg="Waiting for lock file to disappear...")
None __enter__ (self)
None __exit__ (self, type exc_type, Exception exc_val, Any exc_tb)

Protected Member Functions

None _createLockFile (self)
None _createLockFileWindows (self)
None _deleteLockFile (self)
None _deleteLockFileWindows (self)

Protected Attributes

 _filename = filename
 _wait_msg = wait_msg
# Timeout expired. Overwrite the lock file. _timeout = timeout
 _pidfile = None

Detailed Description

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

example usage::

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

Constructor & Destructor Documentation

◆ __init__()

None 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.

:param filename: The name and path of the lockfile to create.
:param timeout: After this amount of seconds, the lock will break
regardless of the state of the file system.
:param wait_msg: A 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

◆ __enter__()

None UM.LockFile.LockFile.__enter__ ( self)
Attempt to grab the lock file for personal use.

◆ __exit__()

None UM.LockFile.LockFile.__exit__ ( self,
type exc_type,
Exception exc_val,
Any exc_tb )
Release the lock file so that other processes may use it.

:param exc_type: The type of exception that was raised during the
    ``with`` block, if any. Use ``None`` if no exception was raised.
:param exc_val: The exception instance that was raised during the
    ``with`` block, if any. Use ``None`` if no exception was raised.
:param exc_tb: The traceback frames at the time the exception occurred,
    if any. Use ``None`` if no exception was raised.

◆ _createLockFile()

None UM.LockFile.LockFile._createLockFile ( self)
protected
Creates the lock file on the file system, with exclusive use.

If another thread wants to use a concurrent folder/file, but this file is still in use, then wait until the
current thread releases the lock file.

◆ _createLockFileWindows()

None UM.LockFile.LockFile._createLockFileWindows ( self)
protected
Creates the lock file on Windows, with exclusive use and with the delete on close flag enabled so in case
the process ends, the file will be automatically removed.

If another thread wants to use a concurrent folder/file, but this file is still in use, then wait until the
current thread releases the lock file.

◆ _deleteLockFile()

None UM.LockFile.LockFile._deleteLockFile ( self)
protected
Close and delete the lock file from the file system once the current thread finish what it was doing.

◆ _deleteLockFileWindows()

None UM.LockFile.LockFile._deleteLockFileWindows ( self)
protected
Close and delete the lock file in Windows using the Windows API. For more info visit:
https://msdn.microsoft.com/en-us/9b84891d-62ca-4ddc-97b7-c4c79482abd9

The documentation for this class was generated from the following file:
  • UM/LockFile.py