mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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:
parent
c2b5ab8d2c
commit
d046e2692c
@ -10,6 +10,7 @@ import socket
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import signal
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ class Instance:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def __read_port_number_from_file(file_path):
|
def __read_port_number_from_file(file_path):
|
||||||
retry_count = 0
|
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)
|
time.sleep(1)
|
||||||
retry_count = retry_count + 1
|
retry_count = retry_count + 1
|
||||||
|
|
||||||
@ -73,6 +74,18 @@ class Instance:
|
|||||||
else:
|
else:
|
||||||
return -1
|
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
|
@staticmethod
|
||||||
def launch(
|
def launch(
|
||||||
resinsight_executable="",
|
resinsight_executable="",
|
||||||
@ -143,7 +156,7 @@ class Instance:
|
|||||||
if port == -1:
|
if port == -1:
|
||||||
print("Unable to read port number. Launch failed.")
|
print("Unable to read port number. Launch failed.")
|
||||||
# Need to kill the process using PID since there is no GRPC connection to use.
|
# Need to kill the process using PID since there is no GRPC connection to use.
|
||||||
os.kill(pid)
|
Instance.__kill_process(pid)
|
||||||
else:
|
else:
|
||||||
instance = Instance(port=port, launched=True)
|
instance = Instance(port=port, launched=True)
|
||||||
return instance
|
return instance
|
||||||
|
Loading…
Reference in New Issue
Block a user