-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
38 lines (27 loc) · 934 Bytes
/
server.py
File metadata and controls
38 lines (27 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import grpc
import time
from concurrent import futures
import sample_pb2
import sample_pb2_grpc
class SampleServicer(sample_pb2_grpc.SampleServicer):
def SampleFunction(self, request, context):
response = sample_pb2.Response()
response.field_1 = "sample123"
response.field_2 = "sample123"
response.field_3 = "sample123"
if len(request.field_mask.ListFields()) > 0:
masked_response = sample_pb2.Response()
request.field_mask.MergeMessage(response, masked_response)
return masked_response
return response
server = grpc.server(futures.ThreadPoolExecutor(max_workers=12))
sample_pb2_grpc.add_SampleServicer_to_server(
SampleServicer(), server)
print('Starting server. Listening on port 5005.')
server.add_insecure_port('[::]:5005')
server.start()
try:
while True:
time.sleep(5)
except KeyboardInterrupt:
server.stop(0)