From 3947a00067b981759e56e96d9daca252d9011856 Mon Sep 17 00:00:00 2001 From: moesnow <11678347+moesnow@users.noreply.github.com> Date: Sun, 15 Oct 2023 14:30:08 +0800 Subject: [PATCH] fix: kill other user processes --- tasks/base/pythonchecker.py | 4 ++-- tasks/game/stop.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tasks/base/pythonchecker.py b/tasks/base/pythonchecker.py index b53e19de..f49e37ef 100644 --- a/tasks/base/pythonchecker.py +++ b/tasks/base/pythonchecker.py @@ -37,7 +37,7 @@ def run(): def install(): download_url = "http://mirrors.huaweicloud.com/python/3.11.5/python-3.11.5-amd64.exe" download_file_path = os.path.join(tempfile.gettempdir(), os.path.basename(download_url)) - destination_path = os.path.join(os.getenv('LocalAppData'), 'Programs\Python\Python311\python.exe') + destination_path = os.path.join(os.getenv('LocalAppData'), r'Programs\Python\Python311\python.exe') while True: try: @@ -86,7 +86,7 @@ def check(path): return False else: logger.debug(_("Python 版本: {version}").format(version=python_version)) - python_arch = subprocess_with_stdout([path, '-c','import platform; print(platform.architecture()[0])']) + python_arch = subprocess_with_stdout([path, '-c', 'import platform; print(platform.architecture()[0])']) logger.debug(_("Python 架构: {arch}").format(arch=python_arch)) if "32" in python_arch: logger.error(_("不支持 32 位 Python")) diff --git a/tasks/game/stop.py b/tasks/game/stop.py index f9de9a02..2d198053 100644 --- a/tasks/game/stop.py +++ b/tasks/game/stop.py @@ -17,9 +17,11 @@ class Stop: @staticmethod def terminate_process(name, timeout=10): + # 获取当前用户的用户名 + current_user = psutil.users()[0].name # 根据进程名中止进程 - for proc in psutil.process_iter(attrs=['pid', 'name']): - if name in proc.info['name']: + for proc in psutil.process_iter(attrs=['pid', 'name', 'username']): + if name in proc.info['name'] and proc.info['username'].split('\\')[-1] == current_user: try: process = psutil.Process(proc.info['pid']) process.terminate()