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/client_s1/compLib/Lock.py
Konstantin Lampalzer 9b567b8c6c Protobuf prototype
2022-03-18 18:11:16 +01: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)