server: tests: ci windows: pid exists better handling

This commit is contained in:
Pierrick HYMBERT 2024-03-10 09:36:37 +01:00
parent eea4f20f06
commit f22a18c90a

View file

@ -1,3 +1,4 @@
import errno
import os import os
import socket import socket
import subprocess import subprocess
@ -67,8 +68,7 @@ def server_kill_hard(context):
print(f"Server dangling exits, hard killing force {pid}={path}...\n") print(f"Server dangling exits, hard killing force {pid}={path}...\n")
if os.name == 'nt': if os.name == 'nt':
process = subprocess.run(['taskkill', '/F', '/pid', str(pid)], process = subprocess.check_output(['taskkill', '/F', '/pid', str(pid)]).decode()
stderr=subprocess.PIPE)
print(process) print(process)
else: else:
os.kill(-pid, signal.SIGKILL) os.kill(-pid, signal.SIGKILL)
@ -85,12 +85,16 @@ def is_server_listening(server_fqdn, server_port):
def pid_exists(pid): def pid_exists(pid):
"""Check whether pid exists in the current process table.""" """Check whether pid exists in the current process table."""
import errno
if pid < 0: if pid < 0:
return False return False
try: if os.name == 'nt':
os.kill(pid, 0) output = subprocess.check_output(['TASKLIST', '/FI', f'pid eq {pid}']).decode()
except OSError as e: print(output)
return e.errno == errno.EPERM return "No tasks are running" not in output
else: else:
return True try:
os.kill(pid, 0)
except OSError as e:
return e.errno == errno.EPERM
else:
return True