Skip to content

Commit ab30b5e

Browse files
Merge pull request #54 from pyansys/medson/clientCheck
Added method common.is_sherlock_client_loading().
2 parents 46c5f01 + ad378e6 commit ab30b5e

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/ansys/sherlock/core/common.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ def check(self):
2828
LOG.info("Connection is up.")
2929
return True
3030

31+
def is_sherlock_client_loading(self):
32+
"""Checks if the Sherlock Client (if opened) is still initializing."""
33+
if not self._is_connection_up():
34+
LOG.error("Not connected to a gRPC service.")
35+
return
36+
37+
message = SherlockCommonService_pb2.IsSherlockClientLoadingRequest()
38+
response = self.stub.isSherlockClientLoading(message)
39+
40+
if response.value == 0:
41+
LOG.info("Sherlock client has finished initializing.")
42+
return True
43+
else:
44+
LOG.error("Sherlock client has not finished initializing.")
45+
return False
46+
3147
def exit(self, close_sherlock_client=False):
3248
"""Close the gRPC connection.
3349

src/ansys/sherlock/core/launcher.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,28 @@ def launch_sherlock(host=LOCALHOST, port=SHERLOCK_DEFAULT_PORT, sherlock_cmd_arg
5454

5555
try:
5656
subprocess.Popen([_get_sherlock_exe_path(), "-grpcPort=" + str(port), sherlock_cmd_args])
57-
time.sleep(10)
57+
time.sleep(5)
5858
except Exception as e:
5959
LOG.error("Error encountered while starting or executing Sherlock, error = " + str(e))
6060

6161
try:
6262
sherlock = connect_grpc_channel(port)
63+
64+
# Check that the gRPC connection is up (timeout after 3 minutes).
65+
count = 0
66+
while sherlock.common.check() is False and count < 90:
67+
time.sleep(2)
68+
count = count + 1
69+
70+
if sherlock.common.check() is False:
71+
raise SherlockConnectionError(message="Error starting gRPC service")
72+
73+
# Check that the Sherlock Client has finished loading (timeout after 5 minutes).
74+
count = 0
75+
while sherlock.common.is_sherlock_client_loading() is False and count < 150:
76+
time.sleep(2)
77+
count = count + 1
78+
6379
return sherlock
6480
except Exception as e:
6581
LOG.error(str(e))
@@ -68,7 +84,6 @@ def launch_sherlock(host=LOCALHOST, port=SHERLOCK_DEFAULT_PORT, sherlock_cmd_arg
6884
def connect_grpc_channel(port=SHERLOCK_DEFAULT_PORT):
6985
"""Create a gRPC connection to the specified port and returns a gRPC connection object ``Sherlock``
7086
which can be used to invoke the APIs from their respective services.."""
71-
global SHERLOCK
7287
channel_param = f"{LOCALHOST}:{port}"
7388
channel = grpc.insecure_channel(channel_param)
7489
SHERLOCK = Sherlock(channel)

0 commit comments

Comments
 (0)