Skip to content

Commit

Permalink
api_v2: use thread pool for blocking operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 5, 2024
1 parent d7cf32e commit c2322a0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/otaclient/grpc/api_v2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import asyncio
import atexit
import logging
from concurrent.futures import ThreadPoolExecutor
from multiprocessing.queues import Queue as mp_Queue
from typing import Callable, NoReturn

Expand Down Expand Up @@ -57,14 +58,18 @@ async def _grpc_server_launcher():
ecu_tracker = ECUTracker(ecu_status_storage, shm_reader)
ecu_tracker.start()

thread_pool = ThreadPoolExecutor(
thread_name_prefix="ota_api_server",
)
api_servicer = OTAClientAPIServicer(
ecu_status_storage=ecu_status_storage,
op_queue=op_queue,
resp_queue=resp_queue,
executor=thread_pool,
)
ota_client_service_v2 = OtaClientServiceV2(api_servicer)

server = grpc.aio.server()
server = grpc.aio.server(migration_thread_pool=thread_pool)
v2_grpc.add_OtaClientServiceServicer_to_server(
server=server, servicer=ota_client_service_v2
)
Expand All @@ -77,5 +82,6 @@ async def _grpc_server_launcher():
await server.wait_for_termination()
finally:
await server.stop(1)
thread_pool.shutdown(wait=True)

asyncio.run(_grpc_server_launcher())

0 comments on commit c2322a0

Please sign in to comment.