|
|
@@ -1195,7 +1195,33 @@ class App(tk.Tk):
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
|
+def _kill_other_instances():
|
|
|
+ """单实例接管:杀掉本机其他 kuaishou_tool.ui 进程(状态全在 sqlite;
|
|
|
+ 在途发布由调度器的30分钟僵尸自愈接手)。失败静默,尽力而为。"""
|
|
|
+ import os
|
|
|
+ import subprocess
|
|
|
+ try:
|
|
|
+ r = subprocess.run(
|
|
|
+ ['powershell', '-Command',
|
|
|
+ "Get-CimInstance Win32_Process -Filter \"name='python.exe'\" "
|
|
|
+ '| Select-Object ProcessId,CommandLine | ConvertTo-Json'],
|
|
|
+ capture_output=True)
|
|
|
+ data = json.loads(r.stdout.decode('gbk', errors='replace') or '[]')
|
|
|
+ if isinstance(data, dict):
|
|
|
+ data = [data]
|
|
|
+ me = os.getpid()
|
|
|
+ for p in data:
|
|
|
+ if 'kuaishou_tool.ui' in (p.get('CommandLine') or '') \
|
|
|
+ and p.get('ProcessId') != me:
|
|
|
+ subprocess.run(['powershell', '-Command',
|
|
|
+ f"Stop-Process -Id {p['ProcessId']} -Force"],
|
|
|
+ capture_output=True)
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
def main():
|
|
|
+ _kill_other_instances() # 无论谁启动(我/用户/双击),只留一个窗口
|
|
|
cfg = config.load()
|
|
|
App(cfg).mainloop()
|
|
|
|