Fix python kill signal (#9320)

* Python: Fix incorrect call to os.kill.

Also make it work on platforms without unix signals.

* Python: Increase process file timeout to one minute.
This commit is contained in:
Kristian Bendiksen 2022-09-29 07:37:31 +02:00 committed by GitHub
parent c2b5ab8d2c
commit d046e2692c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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