This commit is contained in:
Anastasiya Semenkevich 2024-10-04 17:45:36 +03:00
parent ffc5da3805
commit 790c1dcc42
1 changed files with 7 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import logging
import os import os
import signal import signal
import subprocess import subprocess
import time
import typing import typing
import allure import allure
@ -39,12 +40,16 @@ def kill_process(pid):
if get_platform() == "Windows": if get_platform() == "Windows":
subprocess.call(f"taskkill /F /T /PID {str(pid)}") subprocess.call(f"taskkill /F /T /PID {str(pid)}")
elif get_platform() in ["Linux", "Darwin"]: elif get_platform() in ["Linux", "Darwin"]:
os.kill(pid, signal.SIGKILL) p = psutil.Process(pid)
p.kill()
time.sleep(1)
assert not p.is_running()
else: else:
raise NotImplementedError(f"Unsupported platform: {get_platform()}") raise NotImplementedError(f"Unsupported platform: {get_platform()}")
except Exception as e: except Exception as e:
print(f"Failed to terminate process {pid}: {e}") print(f"Failed to terminate process {pid}: {e}")
@allure.step('System execute command') @allure.step('System execute command')
def execute( def execute(
command: list, command: list,
@ -75,6 +80,7 @@ def run(
check=True check=True
) )
@allure.step('Get pid by process name') @allure.step('Get pid by process name')
def get_pid_by_process_name(name): def get_pid_by_process_name(name):
pid_list = [] pid_list = []