I was following a tutorial online on using grpc. I ran into a problem when sending large values. For example if I send 5 I get 5. If I send 1,0000 I get 1,0000 back. But if the number is very large for example 9000000000 it returns 8999999488.0 Why is that? How can I fix this so I get the same value back.
Simple function for checking
def IsPrime(number): return number
server
import grpc from concurrent import futures import time import CheckPrime_pb2 import CheckPrime_pb2_grpc import CheckPrime class CalculatorServicer(CheckPrime_pb2_grpc.CalculatorServicer): def CheckPrime(self, request, context): response = CheckPrime_pb2.Number() response.value = CheckPrime.IsPrime(request.value) return response server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) CheckPrime_pb2_grpc.add_CalculatorServicer_to_server(CalculatorServicer(), server) print('Start server, Listening on port 50051.') server.add_insecure_port('[::]:50051') server.start() try: while True: time.sleep(86500) except KeyboardInterrupt: server.stop(0)
client
import grpc import CheckPrime_pb2 import CheckPrime_pb2_grpc channelname = 'localhost:50051' channel = grpc.insecure_channel(channelname) stub = CheckPrime_pb2_grpc.CalculatorStub(channel) number = CheckPrime_pb2.Number(value= 9000000000) response = stub.CheckPrime(number) print(number) print(response.value)
https://stackoverflow.com/questions/66846748/grpc-python-return-value-is-different-from-input-with-large-numbers March 29, 2021 at 06:20AM
没有评论:
发表评论