Пример #1
0
def serve(db_path, port, workers):
    print(
        f'Starting server on port {port} ({workers} workers | DB @{db_path})')
    server = grpc.server(futures.ThreadPoolExecutor(workers))
    todo_pb2_grpc.add_TodoServiceServicer_to_server(TodoService(db_path),
                                                    server)
    server.add_insecure_port(port)
    server.start()
    server.wait_for_termination()
    print('Server has terminated...')
def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    accounts_pb2_grpc.add_AccountServiceServicer_to_server(
        AccountServiceServicer(), server)
    todo_pb2_grpc.add_TodoServiceServicer_to_server(
        TodoServiceServicer, server)

    server.add_insecure_port('[::]:8081')
    server.start()
    print("Server started")
    server.wait_for_termination()
Пример #3
0
        response.data.extend(todos)
        return response

    def UpdateTodo(self, request, context):
        response = todo_pb2.OperationResponse()
        for todo in self.todoList:
            if todo["id"] == request.id:
                todo["task"] = request.task
                response.todo.id = request.id
                response.todo.task = request.task
                response.status = todo_pb2.OperationResponse.UPDATED
                break
            else:
                response.error = "Task with id doesn't exist"
        return response


server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

todo_pb2_grpc.add_TodoServiceServicer_to_server(TodoServicer(), server)

print("server starting. Listening on port 50051")
server.add_insecure_port('[::]:50051')
server.start()

try:
    while True:
        time.sleep(86400)
except KeyboardInterrupt:
    server.stop(0)
Пример #4
0
def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    todo_pb2_grpc.add_TodoServiceServicer_to_server(TodoService(), server)
    server.add_insecure_port('[::]:50051')
    server.start()
    server.wait_for_termination()
Пример #5
0
    @log_request
    def DeleteTodo(self, request, context):
        try:
            if not request.id:
                raise ValueError("id must be present")
            todo = session.query(Todo).filter(Todo.id == request.id)
            todo.delete(synchronize_session=False)
            logging.info("hai")
            logging.info(todo)
            session.commit()
            return todo_pb2.EmptyRequest()
        except Exception as e:
            print("Exception occured,{0}".format(e.__str__()))
            return Todo()


server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

add_TodoServiceServicer_to_server(TodoServiceServicer(), server)

print('Starting server. Listening on port 50051.')
server.add_insecure_port('[::]:50051')
server.start()

try:
    while True:
        time.sleep(86400)
except KeyboardInterrupt:
    server.stop(0)