Skip to content

Commit

Permalink
Using self._event_loop.call_soon_threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
oandreeva-nv committed Dec 20, 2024
1 parent 0e6f5ef commit 8c30208
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _init_engine(self):
# Run the engine in a separate thread running the AsyncIO event loop.
self._llm_engine = None
self._llm_engine_start_cv = threading.Condition()
self._llm_engine_shutdown_event = threading.Event()
self._llm_engine_shutdown_event = asyncio.Event()
self._event_thread = threading.Thread(
target=asyncio.run, args=(self._run_llm_engine(),)
)
Expand Down Expand Up @@ -268,8 +268,7 @@ async def _run_llm_engine(self):
self._llm_engine_start_cv.notify_all()

# Wait for the engine shutdown signal.
while not self._llm_engine_shutdown_event.is_set():
await asyncio.sleep(0.1) # Prevent busy-waiting
await self._llm_engine_shutdown_event.wait()

# Wait for the ongoing requests to complete.
while self._ongoing_request_count > 0:
Expand Down Expand Up @@ -801,7 +800,7 @@ def _check_health(self, requests):

def finalize(self):
self.logger.log_info("[vllm] Issuing finalize to vllm backend")
self._llm_engine_shutdown_event.set()
self._event_loop.call_soon_threadsafe(self._llm_engine_shutdown_event.set)

# Shutdown the event thread.
if self._event_thread is not None:
Expand Down

0 comments on commit 8c30208

Please sign in to comment.