Skip to content

Commit

Permalink
Python: increase launch timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Sep 4, 2024
1 parent fc2106e commit cd40b27
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions GrpcInterface/Python/rips/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,25 @@ def __is_valid_port(port: int) -> bool:
return True

@staticmethod
def __read_port_number_from_file(file_path: str) -> int:
def __read_port_number_from_file(file_path: str, max_attempts: int) -> int:
retry_count = 0
while not os.path.exists(file_path) and retry_count < 60:
while not os.path.exists(file_path) and retry_count < max_attempts:
time.sleep(1)
retry_count = retry_count + 1

print("Portnumber file retry count : ", retry_count)

if os.path.isfile(file_path):
with open(file_path) as f:
value = f.readline()
return int(value)
else:
return -1

if retry_count == max_attempts:
print(
"Waiting for port number file timed out after {} seconds. File: {}".format(
max_attempts, file_path
)
)

return -1

@staticmethod
def __kill_process(pid: int) -> None:
Expand All @@ -98,6 +103,7 @@ def launch(
resinsight_executable: str = "",
console: bool = False,
launch_port: int = 0,
init_timeout: int = 300,
command_line_parameters: List[str] = [],
) -> Optional[Instance]:
"""Launch a new Instance of ResInsight. This requires the environment variable
Expand All @@ -112,7 +118,7 @@ def launch(
launch_port(int): If 0, GRPC will find an available port.
If -1, use the default port 50051 or RESINSIGHT_GRPC_PORT
If anything else, ResInsight will try to launch with the specified portnumber.
init_timeout: Number of seconds to wait for initialization before timing out.
command_line_parameters(list): Additional parameters as string entries in the list.
Returns:
Instance: an instance object if it worked. None if not.
Expand Down Expand Up @@ -168,7 +174,9 @@ def launch(

pid = os.spawnv(os.P_NOWAIT, resinsight_executable, parameters)
if pid:
port = Instance.__read_port_number_from_file(port_number_file)
port = Instance.__read_port_number_from_file(
port_number_file, init_timeout
)
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.
Expand Down

0 comments on commit cd40b27

Please sign in to comment.