in launcher/sdw_util/Util.py [0:0]
def obtain_lock(basename):
"""
Obtain an exclusive lock during the execution of this process.
"""
lock_file = os.path.join(LOCK_DIRECTORY, basename)
try:
lh = open(lock_file, "w")
except PermissionError:
sdlog.error(
f"Error writing to lock file '{lock_file}'. User may lack the required permissions."
)
return None
try:
# Obtain an exclusive, nonblocking lock
fcntl.lockf(lh, fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError:
sdlog.error(LOCK_ERROR.format(lock_file))
return None
return lh