From ce4423e213e0479ce212b08b4e42b586578f6d66 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Mon, 6 Nov 2023 17:54:35 -0800 Subject: [PATCH] (fix) stability imp: completion() timeout during high traffic, should not raise exception --- litellm/timeout.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/litellm/timeout.py b/litellm/timeout.py index 9a8cba241..a55f31dac 100644 --- a/litellm/timeout.py +++ b/litellm/timeout.py @@ -89,8 +89,15 @@ class _LoopWrapper(Thread): self.loop = asyncio.new_event_loop() def run(self) -> None: - self.loop.run_forever() - self.loop.call_soon_threadsafe(self.loop.close) + try: + self.loop.run_forever() + self.loop.call_soon_threadsafe(self.loop.close) + except Exception as e: + # Log exception here + pass + finally: + self.loop.close() + asyncio.set_event_loop(None) def stop_loop(self): for task in asyncio.all_tasks(self.loop):