lock fixes

This commit is contained in:
Flowseal 2026-04-07 17:01:42 +03:00
parent 826554abfb
commit 6231499c39
1 changed files with 16 additions and 11 deletions

View File

@ -60,12 +60,6 @@ def _same_process(meta: dict, proc: psutil.Process, script_hint: str) -> bool:
return False return False
if IS_FROZEN: if IS_FROZEN:
return APP_NAME.lower() in proc.name().lower() return APP_NAME.lower() in proc.name().lower()
try:
for arg in proc.cmdline():
if script_hint in arg:
return True
except Exception:
pass
return False return False
@ -76,7 +70,10 @@ def acquire_lock(script_hint: str = "") -> bool:
try: try:
pid = int(f.stem) pid = int(f.stem)
except Exception: except Exception:
try:
f.unlink(missing_ok=True) f.unlink(missing_ok=True)
except OSError:
pass
continue continue
meta: dict = {} meta: dict = {}
try: try:
@ -85,12 +82,17 @@ def acquire_lock(script_hint: str = "") -> bool:
meta = json.loads(raw) meta = json.loads(raw)
except Exception: except Exception:
pass pass
is_running = False
try: try:
if _same_process(meta, psutil.Process(pid), script_hint): is_running = _same_process(meta, psutil.Process(pid), script_hint)
return False
except Exception: except Exception:
pass pass
if is_running:
return False
try:
f.unlink(missing_ok=True) f.unlink(missing_ok=True)
except OSError:
pass
lock_file = APP_DIR / f"{os.getpid()}.lock" lock_file = APP_DIR / f"{os.getpid()}.lock"
try: try:
@ -100,7 +102,10 @@ def acquire_lock(script_hint: str = "") -> bool:
encoding="utf-8", encoding="utf-8",
) )
except Exception: except Exception:
try:
lock_file.touch() lock_file.touch()
except Exception:
pass
_lock_file_path = lock_file _lock_file_path = lock_file
return True return True