From f22a18c90ad820503d1b67ad727783e8e5c89f0c Mon Sep 17 00:00:00 2001 From: Pierrick HYMBERT Date: Sun, 10 Mar 2024 09:36:37 +0100 Subject: [PATCH] server: tests: ci windows: pid exists better handling --- examples/server/tests/features/environment.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/server/tests/features/environment.py b/examples/server/tests/features/environment.py index ff474fc8d..8ad987e1b 100644 --- a/examples/server/tests/features/environment.py +++ b/examples/server/tests/features/environment.py @@ -1,3 +1,4 @@ +import errno import os import socket import subprocess @@ -67,8 +68,7 @@ def server_kill_hard(context): print(f"Server dangling exits, hard killing force {pid}={path}...\n") if os.name == 'nt': - process = subprocess.run(['taskkill', '/F', '/pid', str(pid)], - stderr=subprocess.PIPE) + process = subprocess.check_output(['taskkill', '/F', '/pid', str(pid)]).decode() print(process) else: os.kill(-pid, signal.SIGKILL) @@ -85,12 +85,16 @@ def is_server_listening(server_fqdn, server_port): def pid_exists(pid): """Check whether pid exists in the current process table.""" - import errno if pid < 0: return False - try: - os.kill(pid, 0) - except OSError as e: - return e.errno == errno.EPERM + if os.name == 'nt': + output = subprocess.check_output(['TASKLIST', '/FI', f'pid eq {pid}']).decode() + print(output) + return "No tasks are running" not in output else: - return True + try: + os.kill(pid, 0) + except OSError as e: + return e.errno == errno.EPERM + else: + return True