Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Fix _kill_process AttributeError when _stats_logger is unset (#6417)
Daniel Han1b697ed6fcc2
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 31e5d9dec08..062944264ab 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -6125,7 +6125,9 @@ class LlamaCppBackend:except Exception as e:logger.warning(f"Error killing llama-server process: {e}")finally:- if self._stats_logger is not None:+ # getattr: teardown must tolerate a partially-built backend (failed+ # __init__ or a __new__-built instance), as with _llama_log_fh below.+ if getattr(self, "_stats_logger", None) is not None:self._stats_logger.stop()self._stats_logger = Noneself._process = None@@ -6135,8 +6137,9 @@ class LlamaCppBackend:# Drives _wait_for_vram_settle in the next load_model; set in finally# so both in-process and frontend Apply paths record the kill.self._last_kill_monotonic = time.monotonic()- if self._stdout_thread is not None:- self._stdout_thread.join(timeout = 2)+ stdout_thread = getattr(self, "_stdout_thread", None)+ if stdout_thread is not None:+ stdout_thread.join(timeout = 2)self._stdout_thread = Nonefh = getattr(self, "_llama_log_fh", None)if fh is not None:diff --git a/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py b/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.pyindex 91979e3e0fb..c103c6394a9 100644--- a/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py+++ b/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py@@ -309,6 +309,26 @@ def test_kill_process_records_timestamp_on_actual_kill():assert before <= backend._last_kill_monotonic <= after+def test_kill_process_tolerates_partially_constructed_backend():+ # Teardown must not AttributeError on a __new__-built backend that never ran+ # __init__: _stats_logger / _stdout_thread / _llama_log_fh are left unset.+ backend = LlamaCppBackend.__new__(LlamaCppBackend)++ class _FakeProcess:+ def terminate(self):+ pass++ def wait(self, timeout = None):+ return 0++ def kill(self):+ pass++ backend._process = _FakeProcess()+ backend._kill_process()+ assert backend._process is None++def test_helper_is_static_method_callable_off_class():"""Pin the @staticmethod binding so call sites can invoke off the class."""ctx, _state = _patch_probe([[]])