From 86438b11f30ab9c8419348f63f85b2a4405c84e1 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sun, 14 Dec 2025 18:56:15 -0500 Subject: [PATCH] Handle stale updater lockfiles by removing dead PID entries --- pikit_api/releases.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pikit_api/releases.py b/pikit_api/releases.py index 0490258..5bd9c6c 100644 --- a/pikit_api/releases.py +++ b/pikit_api/releases.py @@ -400,6 +400,19 @@ def fetch_text_with_auth(url: str): def acquire_lock(): try: ensure_dir(UPDATE_LOCK.parent) + # Clear stale lock if the recorded PID is not running + if UPDATE_LOCK.exists(): + try: + pid = int(UPDATE_LOCK.read_text().strip() or "0") + if pid > 0: + os.kill(pid, 0) + else: + UPDATE_LOCK.unlink(missing_ok=True) + except OSError: + # Process not running + UPDATE_LOCK.unlink(missing_ok=True) + except Exception: + UPDATE_LOCK.unlink(missing_ok=True) lockfile = UPDATE_LOCK.open("w") fcntl.flock(lockfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) lockfile.write(str(os.getpid()))