Skip to content

Commit

Permalink
fix: kill other user processes
Browse files Browse the repository at this point in the history
  • Loading branch information
moesnow committed Oct 15, 2023
1 parent fd4ae11 commit 3947a00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tasks/base/pythonchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"))
Expand Down
6 changes: 4 additions & 2 deletions tasks/game/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3947a00

Please sign in to comment.