Пожалуйста, обратитесь ниже код:
import grpc
from concurrent import futures
import time
import calculator_pb2
import calculator_pb2_grpc
import calculator
class CalculatorServicer(calculator_pb2_grpc.CalculatorServicer):
def SquareRoot(selfself, request, context):
response = calculator_pb2.Number()
response.value = calculator.square_root((request.value))
return response
# creating grpc server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
calculator_pb2_grpc.add_CalculatorServicer_to_server(CalculatorServicer(), server)
print('Starting server. Listening on port 50051.')
server.add_insecure_port('[::]:50051')
server.start()
# below line is what keeping server alive
try:
while True:
time.sleep(86400)
except KeyboardInterrupt:
server.stop(0)
**********************************
try: while True: time.sleep (86400) кроме KeyboardInterrupt: server.stop (0)
***********************************
В приведенном выше блоке кода можно не ставить условие сна, и все равно сервер будет жив?