Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: Add atexit handler to flush log queue on program exit

LearningCircuitd4d583a3f827
diff --git a/src/local_deep_research/web/app.py b/src/local_deep_research/web/app.py
index 0f432ee3e5..5be7bcaefe 100644
--- a/src/local_deep_research/web/app.py
+++ b/src/local_deep_research/web/app.py
@@ -1,6 +1,7 @@
+import atexit
from loguru import logger
-from ..utilities.log_utils import config_logger
+from ..utilities.log_utils import config_logger, flush_log_queue
from .app_factory import create_app
@@ -13,6 +14,22 @@ def main():
# Configure logging with milestone level
config_logger("ldr_web")
+ # Register atexit handler to flush logs on exit
+ def flush_logs_on_exit():
+ """Flush any pending logs when the program exits."""
+ try:
+ # Create a minimal Flask app context to allow database access
+ from flask import Flask
+
+ app = Flask(__name__)
+ with app.app_context():
+ flush_log_queue()
+ except Exception as e:
+ logger.exception(f"Failed to flush logs on exit: {e}")
+
+ atexit.register(flush_logs_on_exit)
+ logger.debug("Registered atexit handler for log flushing")
+
# Create the Flask app and SocketIO instance
app, socket_service = create_app()