mirror of
https://github.com/Flowseal/tg-ws-proxy.git
synced 2026-09-06 10:07:02 +00:00
lock fixes
This commit is contained in:
+16
-11
@@ -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:
|
||||||
f.unlink(missing_ok=True)
|
try:
|
||||||
|
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
|
||||||
f.unlink(missing_ok=True)
|
if is_running:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
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:
|
||||||
lock_file.touch()
|
try:
|
||||||
|
lock_file.touch()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
_lock_file_path = lock_file
|
_lock_file_path = lock_file
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user