(address)
| 617 | return backend_pb2.Result(success=True) |
| 618 | |
| 619 | async def serve(address): |
| 620 | # Start asyncio gRPC server |
| 621 | server = grpc.aio.server(migration_thread_pool=futures.ThreadPoolExecutor(max_workers=MAX_WORKERS), |
| 622 | options=[ |
| 623 | ('grpc.max_message_length', 50 * 1024 * 1024), # 50MB |
| 624 | ('grpc.max_send_message_length', 50 * 1024 * 1024), # 50MB |
| 625 | ('grpc.max_receive_message_length', 50 * 1024 * 1024), # 50MB |
| 626 | ], |
| 627 | interceptors=get_auth_interceptors(aio=True), |
| 628 | ) |
| 629 | # Add the servicer to the server |
| 630 | backend_pb2_grpc.add_BackendServicer_to_server(BackendServicer(), server) |
| 631 | # Bind the server to the address |
| 632 | server.add_insecure_port(address) |
| 633 | |
| 634 | # Gracefully shutdown the server on SIGTERM or SIGINT |
| 635 | loop = asyncio.get_event_loop() |
| 636 | for sig in (signal.SIGINT, signal.SIGTERM): |
| 637 | loop.add_signal_handler( |
| 638 | sig, lambda: asyncio.ensure_future(server.stop(5)) |
| 639 | ) |
| 640 | |
| 641 | # Start the server |
| 642 | await server.start() |
| 643 | print("Server started. Listening on: " + address, file=sys.stderr) |
| 644 | # Wait for the server to be terminated |
| 645 | await server.wait_for_termination() |
| 646 | |
| 647 | if __name__ == "__main__": |
| 648 | parser = argparse.ArgumentParser(description="Run the gRPC server.") |
no test coverage detected