-
Notifications
You must be signed in to change notification settings - Fork 1
/
grpc_server.py
35 lines (28 loc) · 910 Bytes
/
grpc_server.py
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
from concurrent import futures
import threading
import grpc
import storage_pb2
import storage_pb2_grpc
import time
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Listener(storage_pb2_grpc.FileServerServicer):
"""The listener function implemests the rpc call as described in the .proto file"""
def __init__(self):
print('initialization')
def upload_chunk_stream(self, request, context):
for c in request:
print(c.chunk)
return storage_pb2.ResponseBoolean(success = False)
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
storage_pb2_grpc.add_FileServerServicer_to_server(
Listener(), server)
server.add_insecure_port('[::]:2750')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()