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.

Fix issues with the benchmark script (#435)

Daniel Petti00e47b214c45
diff --git a/examples/benchmarks/run_resumable_parallel_benchmark.py b/examples/benchmarks/run_resumable_parallel_benchmark.py
index 17e39eda1d..6196c5686a 100644
--- a/examples/benchmarks/run_resumable_parallel_benchmark.py
+++ b/examples/benchmarks/run_resumable_parallel_benchmark.py
@@ -441,7 +441,8 @@ def main():
"iterations": 8, # Increased for BrowseComp with source-based strategy
"questions_per_iteration": 5, # Good for source-based strategy
"search_tool": "searxng",
- "search_strategy": "source_based", # Test source-based strategy performance
+ "search_strategy": "source-based", # Test source-based strategy
+ # performance
}
# Add model configurations if provided
diff --git a/src/local_deep_research/utilities/threading_utils.py b/src/local_deep_research/utilities/threading_utils.py
index 01162fe8a1..b8968a833e 100644
--- a/src/local_deep_research/utilities/threading_utils.py
+++ b/src/local_deep_research/utilities/threading_utils.py
@@ -1,6 +1,7 @@
import threading
from functools import wraps
from typing import Any, Callable, Tuple
+from loguru import logger
from cachetools import cached, keys
from flask import current_app, g
@@ -47,29 +48,43 @@ def thread_with_app_context(to_wrap: Callable) -> Callable:
@wraps(to_wrap)
def _run_with_context(
- app_context: AppContext, *args: Any, **kwargs: Any
+ app_context: AppContext | None, *args: Any, **kwargs: Any
) -> Any:
+ if app_context is None:
+ # Do nothing.
+ return to_wrap(*args, **kwargs)
+
with app_context:
return to_wrap(*args, **kwargs)
return _run_with_context
-def thread_context() -> AppContext:
+def thread_context() -> AppContext | None:
"""
Pushes a new app context for a thread that is being spawned to handle the
current request. Will copy all the global data from the current context.
Returns:
- The new context.
+ The new context, or None if no context is active.
"""
# Copy global data.
global_data = {}
- for key in g:
- global_data[key] = g.get(key)
+ try:
+ for key in g:
+ global_data[key] = g.get(key)
+ except TypeError:
+ # Context is not initialized. Don't change anything.
+ pass
+
+ try:
+ context = current_app.app_context()
+ except RuntimeError:
+ # Context is not initialized.
+ logger.debug("No current app context, not passing to thread.")
+ return None
- context = current_app.app_context()
with context:
for key, value in global_data.items():
setattr(g, key, value)