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()