blob: 8be0651199c2824146eb306bf696da09f3b865a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import os
import tempfile
lock_dir_path = os.path.join(tempfile.gettempdir(), "rwa-session-service")
lock_file_path = os.path.join(lock_dir_path, "rwa-session-service.lock")
def lock():
"""Create lock file."""
os.makedirs(lock_dir_path, exist_ok=True)
with open(lock_file_path, "w") as f:
f.write("lock")
def is_locked():
"""Check if the lock file exists."""
return os.path.exists(lock_file_path)
def unlock():
"""Remove the lock file."""
try:
os.remove(lock_file_path)
except FileNotFoundError:
pass
|