From 16ed7e8c93d7481d8b426746af9ec3ffa323f450 Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Wed, 5 Apr 2023 08:11:07 +0200 Subject: [PATCH] Add signal windows Signed-off-by: Irene Bandera --- .../test/application/test_class.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fastddsspy_tool/test/application/test_class.py b/fastddsspy_tool/test/application/test_class.py index 5747a386..8562ddf1 100644 --- a/fastddsspy_tool/test/application/test_class.py +++ b/fastddsspy_tool/test/application/test_class.py @@ -31,6 +31,7 @@ import signal import re import time +import os DESCRIPTION = """Script to execute Fast DDS Spy executable test""" USAGE = ('python3 tests.py -e ' @@ -138,13 +139,27 @@ def run_dds(self): stderr=subprocess.PIPE) return proc + def is_linux(self): + """Return whether the script is running in a Linux environment.""" + return os.name == 'posix' + + def is_windows(self): + """Return whether the script is running in a Windows environment.""" + return os.name == 'nt' + def stop_dds(self, proc): # send a ctrl+c signal to the subprocess - proc.send_signal(signal.SIGINT) + if self.is_linux(): + proc.send_signal(signal.SIGINT) + elif self.is_windows(): + proc.send_signal(signal.CTRL_C_EVENT) try: proc.communicate(timeout=5) except subprocess.TimeoutExpired: - proc.send_signal(signal.SIGINT) + if self.is_linux(): + proc.send_signal(signal.SIGINT) + elif self.is_windows(): + proc.send_signal(signal.CTRL_C_EVENT) proc.communicate() def valid_returncode(self, returncode):