This repository has been archived on 2025-06-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compLIB/compLib/Lock.py
2022-02-13 17:30:10 +00:00

25 lines
No EOL
516 B
Python

from filelock import FileLock, Timeout
import atexit
FILELOCK_PATH = "/root/complib.lock"
global_lock = FileLock(FILELOCK_PATH, timeout=1)
class Lock(object):
@staticmethod
def lock():
global_lock.acquire()
@staticmethod
def unlock():
global_lock.release()
@staticmethod
def is_locked():
try:
global_lock.acquire()
global_lock.release()
return False
except Timeout:
return True
atexit.register(Lock.unlock)