arflow.serve

Simple server for ARFlow service.

 1"""Simple server for ARFlow service."""
 2
 3import sys
 4from concurrent import futures
 5
 6import grpc
 7
 8from arflow import service_pb2_grpc
 9from arflow.core import ARFlowService
10
11
12def create_server(
13    service: ARFlowService, port: int = 8500, path_to_save: str | None = None
14):
15    """Run gRPC server."""
16    try:
17        service = service()
18        server = grpc.server(
19            futures.ThreadPoolExecutor(max_workers=10),
20            options=[
21                ("grpc.max_send_message_length", -1),
22                ("grpc.max_receive_message_length", -1),
23            ],
24        )
25        service_pb2_grpc.add_ARFlowServiceServicer_to_server(service, server)
26        server.add_insecure_port("[::]:%s" % port)
27        server.start()
28
29        print(f"ARFlow server started on port {port}")
30        server.wait_for_termination()
31    except KeyboardInterrupt:
32        if path_to_save is not None:
33            service.on_program_exit(path_to_save)
34        sys.exit(0)
35
36    # except Exception as e:
37    #     print(e)
38
39
40def serve():
41    """Run a simple ARFlow server."""
42    create_server(ARFlowService)
43
44
45if __name__ == "__main__":
46    serve()
def create_server( service: arflow.core.ARFlowService, port: int = 8500, path_to_save: str | None = None):
13def create_server(
14    service: ARFlowService, port: int = 8500, path_to_save: str | None = None
15):
16    """Run gRPC server."""
17    try:
18        service = service()
19        server = grpc.server(
20            futures.ThreadPoolExecutor(max_workers=10),
21            options=[
22                ("grpc.max_send_message_length", -1),
23                ("grpc.max_receive_message_length", -1),
24            ],
25        )
26        service_pb2_grpc.add_ARFlowServiceServicer_to_server(service, server)
27        server.add_insecure_port("[::]:%s" % port)
28        server.start()
29
30        print(f"ARFlow server started on port {port}")
31        server.wait_for_termination()
32    except KeyboardInterrupt:
33        if path_to_save is not None:
34            service.on_program_exit(path_to_save)
35        sys.exit(0)
36
37    # except Exception as e:
38    #     print(e)

Run gRPC server.

def serve():
41def serve():
42    """Run a simple ARFlow server."""
43    create_server(ARFlowService)

Run a simple ARFlow server.