diff --git a/cecli/models.py b/cecli/models.py index 4148682b44b..b9ddccca402 100644 --- a/cecli/models.py +++ b/cecli/models.py @@ -1378,6 +1378,11 @@ async def simple_send_with_retries( continue except AttributeError: return None + except KeyboardInterrupt: + # An interrupt was not caught within the async run loop. + # We'll just pass to allow the thread to exit gracefully + # without a scary traceback. + pass def model_error_response(self): return litellm.ModelResponse( diff --git a/cecli/tui/worker.py b/cecli/tui/worker.py index 259ca0775eb..5a19e1567a4 100644 --- a/cecli/tui/worker.py +++ b/cecli/tui/worker.py @@ -49,10 +49,9 @@ def _run_thread(self): try: self.loop.run_until_complete(self._async_run()) - except asyncio.CancelledError: - pass - except RuntimeError: - # Event loop stopped - this is expected during shutdown + except BaseException: + # Catch anything that could bring down the thread, and just let it exit. + # This includes KeyboardInterrupt, SystemExit, etc. pass finally: self._cleanup_loop() @@ -188,11 +187,6 @@ def stop(self): # We'll just pass to allow the thread to exit gracefully # without a scary traceback. pass - except KeyboardInterrupt: - # An interrupt was not caught within the async run loop. - # We'll just pass to allow the thread to exit gracefully - # without a scary traceback. - pass self.interrupt() # Wait for thread to finish