diff --git a/GrpcInterface/Python/rips/instance.py b/GrpcInterface/Python/rips/instance.py index d482221c9a..475f364f12 100644 --- a/GrpcInterface/Python/rips/instance.py +++ b/GrpcInterface/Python/rips/instance.py @@ -10,6 +10,7 @@ import socket import logging import time import tempfile +import signal import grpc @@ -60,7 +61,7 @@ class Instance: @staticmethod def __read_port_number_from_file(file_path): retry_count = 0 - while not os.path.exists(file_path) and retry_count < 30: + while not os.path.exists(file_path) and retry_count < 60: time.sleep(1) retry_count = retry_count + 1 @@ -73,6 +74,18 @@ class Instance: else: return -1 + @staticmethod + def __kill_process(pid): + """ + Kill the process with a given pid. + """ + if hasattr(signal, "CTRL_C_EVENT"): + # windows does not have kill + os.kill(pid, signal.CTRL_C_EVENT) + else: + # linux/unix + os.kill(pid, signal.SIGKILL) + @staticmethod def launch( resinsight_executable="", @@ -143,7 +156,7 @@ class Instance: if port == -1: print("Unable to read port number. Launch failed.") # Need to kill the process using PID since there is no GRPC connection to use. - os.kill(pid) + Instance.__kill_process(pid) else: instance = Instance(port=port, launched=True) return instance