Source code for babao.utils.lock

"""Some utils functions for lock file handling"""

import os

[docs]def isLocked(lockfile): """Check if the ´lockfile´ exists""" return os.path.isdir(lockfile)
[docs]def tryLock(lockfile): """ Create the given ´lockfile´ Return false if it already exists """ if isLocked(lockfile): return False os.mkdir(lockfile) return True
[docs]def tryUnlock(lockfile): """ Remove the given ´lockfile´ Return false if it doesn't exist """ if not isLocked(lockfile): return False os.rmdir(lockfile) return True