Skip to content

Commit 0bb1805

Browse files
catch RpcError due to change in GRPC (#125)
1 parent 2884ced commit 0bb1805

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/tf_container/proxy_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
2+
#
33
# Licensed under the Apache License, Version 2.0 (the "License").
44
# You may not use this file except in compliance with the License.
55
# A copy of the License is located at
6-
#
6+
#
77
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# or in the "license" file accompanying this file. This file is distributed
10-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
# express or implied. See the License for the specific language governing
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
1313

1414
import numpy as np

src/tf_container/serve.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import google.protobuf.json_format as json_format
2121
import os
2222

23-
from grpc import StatusCode
23+
from grpc import StatusCode, RpcError
2424
from grpc.framework.interfaces.face.face import AbortionError
2525
from tensorflow.core.framework import tensor_pb2
2626
from tf_container import proxy_client
@@ -130,15 +130,26 @@ def _wait_model_to_load(grpc_proxy_client, max_seconds):
130130

131131
logger.info("TF Serving model successfully loaded")
132132
return
133-
except AbortionError as err:
134-
if err.code == StatusCode.UNAVAILABLE:
135-
logger.info("Waiting for TF Serving to load the model")
136-
time.sleep(1)
133+
except AbortionError as abort_err:
134+
if abort_err.code == StatusCode.UNAVAILABLE:
135+
_handle_rpc_exception(abort_err)
136+
# GRPC throws a _Rendezvous, which inherits from RpcError
137+
# _Rendezvous has a method for code instead of a parameter.
138+
# https://github.com/grpc/grpc/issues/9270
139+
except RpcError as rpc_error:
140+
if rpc_error.code() == StatusCode.UNAVAILABLE:
141+
_handle_rpc_exception(rpc_error)
137142

138143
message = 'TF Serving failed to load the model under the maximum load time in seconds: {}'
139144
raise ValueError(message.format(max_seconds))
140145

141146

147+
def _handle_rpc_exception(err):
148+
logger.info("Waiting for TF Serving to load the model due to {}"
149+
.format(err.__class__.__name__))
150+
time.sleep(1)
151+
152+
142153
class Transformer(object):
143154
"""A ``Transformer`` encapsulates the function(s) responsible
144155
for parsing incoming request data, passing it through an and converting the result into something

0 commit comments

Comments
 (0)