Files
tg-admin-bot/locks.py
2026-02-07 21:34:24 +03:00

18 lines
376 B
Python

from pathlib import Path
import time
LOCK_DIR = Path("/var/run/tg-bot")
LOCK_DIR.mkdir(exist_ok=True)
def acquire(name: str) -> bool:
path = LOCK_DIR / f"{name}.lock"
if path.exists():
return False
path.write_text(str(time.time()))
return True
def release(name: str):
path = LOCK_DIR / f"{name}.lock"
if path.exists():
path.unlink()