Skip to content

Commit dfc0d6c

Browse files
authored
Merge pull request #36 from Yoctol/use-grpclib
Use grpclib not aiorpc
2 parents 34a2008 + 78d4d44 commit dfc0d6c

30 files changed

Lines changed: 1744 additions & 190 deletions

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,4 @@ dump.rdb
9696
.vscode/
9797
.pytest_cache/
9898

99-
**/*_pb2*
10099
.fake-models

Pipfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ url = "https://pypi.org/simple"
33
verify_ssl = true
44
name = "pypi"
55

6-
76
[packages]
87
serving-utils = {editable = true, path = "."}
98

10-
119
[dev-packages]
1210
pytest = "*"
1311
"flake8-config-yoctol" = ">=0.0.11"
1412
pytest-asyncio = "*"
1513

16-
1714
[requires]
1815
python_version = "3.6"

Pipfile.lock

Lines changed: 249 additions & 154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ make test
102102
```
103103
make install-dev
104104
```
105+
106+
### Protos
107+
108+
```
109+
python -m grpc_tools.protoc -I. --python_out=. --python_grpc_out=. --grpc_python_out=. serving_utils/protos/*.proto
110+
```

serving_utils/client.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from collections import namedtuple
66
from concurrent.futures import ThreadPoolExecutor
77

8-
from aiogrpc import Channel
98
import grpc
9+
from grpclib.client import Channel
1010
import tensorflow as tf
1111

1212
from .protos import predict_pb2, prediction_service_pb2_grpc, list_models_pb2, list_models_pb2_grpc
13+
from .protos import prediction_service_grpc
1314

1415

1516
def copy_message(src, dst):
@@ -66,15 +67,18 @@ def __init__(
6667
credentials=creds,
6768
options=channel_options,
6869
)
69-
self._async_channel = Channel(
70-
self._channel,
71-
loop=loop,
72-
executor=executor,
73-
standalone_pool_for_streaming=standalone_pool_for_streaming,
74-
)
70+
71+
if loop is None:
72+
loop = asyncio.get_event_loop()
73+
74+
split_addr = addr.split(':')
75+
host = split_addr[0]
76+
port = split_addr[1]
77+
# TODO: better addr parsing, secure channel
78+
self._async_channel = Channel(host, port, loop=loop)
7579

7680
self._stub = prediction_service_pb2_grpc.PredictionServiceStub(self._channel)
77-
self._async_stub = prediction_service_pb2_grpc.PredictionServiceStub(self._async_channel)
81+
self._async_stub = prediction_service_grpc.PredictionServiceStub(self._async_channel)
7882
self._check_address_health()
7983

8084
def _check_address_health(self):
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by the Protocol Buffers compiler. DO NOT EDIT!
2+
# source: serving_utils/protos/list_models.proto
3+
# plugin: grpclib.plugin.main
4+
import abc
5+
6+
import grpclib.const
7+
import grpclib.client
8+
9+
import serving_utils.protos.list_models_pb2
10+
11+
12+
class ListModelsBase(abc.ABC):
13+
14+
@abc.abstractmethod
15+
async def ListModels(self, stream):
16+
pass
17+
18+
def __mapping__(self):
19+
return {
20+
'/ListModels/ListModels': grpclib.const.Handler(
21+
self.ListModels,
22+
grpclib.const.Cardinality.UNARY_UNARY,
23+
serving_utils.protos.list_models_pb2.ListModelsRequest,
24+
serving_utils.protos.list_models_pb2.ListModelsResponse,
25+
),
26+
}
27+
28+
29+
class ListModelsStub:
30+
31+
def __init__(self, channel: grpclib.client.Channel) -> None:
32+
self.ListModels = grpclib.client.UnaryUnaryMethod(
33+
channel,
34+
'/ListModels/ListModels',
35+
serving_utils.protos.list_models_pb2.ListModelsRequest,
36+
serving_utils.protos.list_models_pb2.ListModelsResponse,
37+
)

serving_utils/protos/list_models_pb2.py

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
import grpc
3+
4+
from serving_utils.protos import list_models_pb2 as serving__utils_dot_protos_dot_list__models__pb2
5+
6+
7+
class ListModelsStub(object):
8+
# missing associated documentation comment in .proto file
9+
pass
10+
11+
def __init__(self, channel):
12+
"""Constructor.
13+
14+
Args:
15+
channel: A grpc.Channel.
16+
"""
17+
self.ListModels = channel.unary_unary(
18+
'/ListModels/ListModels',
19+
request_serializer=serving__utils_dot_protos_dot_list__models__pb2.ListModelsRequest.SerializeToString,
20+
response_deserializer=serving__utils_dot_protos_dot_list__models__pb2.ListModelsResponse.FromString,
21+
)
22+
23+
24+
class ListModelsServicer(object):
25+
# missing associated documentation comment in .proto file
26+
pass
27+
28+
def ListModels(self, request, context):
29+
# missing associated documentation comment in .proto file
30+
pass
31+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
32+
context.set_details('Method not implemented!')
33+
raise NotImplementedError('Method not implemented!')
34+
35+
36+
def add_ListModelsServicer_to_server(servicer, server):
37+
rpc_method_handlers = {
38+
'ListModels': grpc.unary_unary_rpc_method_handler(
39+
servicer.ListModels,
40+
request_deserializer=serving__utils_dot_protos_dot_list__models__pb2.ListModelsRequest.FromString,
41+
response_serializer=serving__utils_dot_protos_dot_list__models__pb2.ListModelsResponse.SerializeToString,
42+
),
43+
}
44+
generic_handler = grpc.method_handlers_generic_handler(
45+
'ListModels', rpc_method_handlers)
46+
server.add_generic_rpc_handlers((generic_handler,))

serving_utils/protos/model_grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Generated by the Protocol Buffers compiler. DO NOT EDIT!
2+
# source: serving_utils/protos/model.proto
3+
# plugin: grpclib.plugin.main

serving_utils/protos/model_pb2.py

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)