chore: terminate process on windows
This commit is contained in:
parent
eb9c629bbf
commit
dc628f300a
|
@ -26,7 +26,7 @@ def application_logs():
|
||||||
for app_data in configs.testpath.STATUS_DATA.iterdir():
|
for app_data in configs.testpath.STATUS_DATA.iterdir():
|
||||||
for log in (app_data / 'logs').glob('*.log'):
|
for log in (app_data / 'logs').glob('*.log'):
|
||||||
allure.attach.file(log, name=str(log.name), attachment_type=allure.attachment_type.TEXT)
|
allure.attach.file(log, name=str(log.name), attachment_type=allure.attachment_type.TEXT)
|
||||||
log.unlink()
|
log.unlink() # FIXME: it does not work on Windows, permission error
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
@ -2,14 +2,13 @@ import logging
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
|
||||||
import typing
|
import typing
|
||||||
|
import platform
|
||||||
|
|
||||||
import allure
|
import allure
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
import configs
|
import configs
|
||||||
from configs.system import IS_WIN
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -33,22 +32,20 @@ def find_free_port(start: int, step: int):
|
||||||
|
|
||||||
|
|
||||||
@allure.step('Kill process')
|
@allure.step('Kill process')
|
||||||
def kill_process(pid, sig: signal.Signals = signal.SIGKILL):
|
def kill_process(pid):
|
||||||
LOG.debug('Sending %s to %d process', sig.name, pid)
|
LOG.debug(f'Terminating process {pid}')
|
||||||
try:
|
|
||||||
p = psutil.Process(pid)
|
current_platform = platform.system()
|
||||||
|
|
||||||
except ProcessLookupError as err:
|
|
||||||
LOG.error('Failed to find process %d: %s', pid, err)
|
|
||||||
raise err
|
|
||||||
for i in range(2):
|
|
||||||
try:
|
try:
|
||||||
LOG.warning('Waiting for process to exit: %d', pid)
|
if current_platform == "Windows":
|
||||||
p.kill()
|
subprocess.call(f"taskkill /F /T /PID {str(pid)}")
|
||||||
if not p.is_running():
|
elif current_platform in ["Linux", "Darwin"]:
|
||||||
break
|
os.kill(pid, signal.SIGKILL)
|
||||||
except RuntimeError:
|
else:
|
||||||
raise ('Failed to kill process: %d' % pid)
|
raise NotImplementedError(f"Unsupported platform: {current_platform}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to terminate process {pid}: {e}")
|
||||||
|
|
||||||
|
|
||||||
@allure.step('System execute command')
|
@allure.step('System execute command')
|
||||||
|
|
Loading…
Reference in New Issue