Skip to content

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.

tests: keep the Kaggle launcher's signal handlers out of the pytest worker (#12974)

Daniel Han9fafe41edbf2
diff --git a/tests/kaggle/conftest.py b/tests/kaggle/conftest.py
index 8371660867a..5022c7ffb75 100644
--- a/tests/kaggle/conftest.py
+++ b/tests/kaggle/conftest.py
@@ -17,6 +17,7 @@ tests that never think about credentials at all.
from __future__ import annotations
+import signal
import sys
from pathlib import Path
@@ -41,3 +42,33 @@ _OTHER_CREDENTIAL_ENVS = ("KAGGLE_KEY", "KAGGLE_USERNAME", "KAGGLE_ACCESS_TOKEN_
def _no_ambient_kaggle_credentials(monkeypatch):
for name in (*DEFAULT_ACCOUNT_ENVS, *_OTHER_CREDENTIAL_ENVS):
monkeypatch.delenv(name, raising = False)
+
+
+_RELEASE_SIGNALS = tuple(
+ sig
+ for sig in (signal.SIGINT, signal.SIGTERM, getattr(signal, "SIGHUP", None))
+ if sig is not None
+)
+
+
[email protected](autouse = True)
+def _no_process_wide_release_handlers(monkeypatch):
+ """`launch.main()` installs SIGINT/SIGTERM/SIGHUP handlers and an atexit hook for its whole process.
+
+ In a pytest worker those outlive the test: the next test that sends itself SIGTERM
+ (tests/test_decision_gguf.py) reached `_release_and_die` instead of its own handler, which
+ re-raised the signal and killed the xdist worker. The handlers have their own tests, which run
+ them in a subprocess (test_launch_cleanup.py). Any other test here that leaves a disposition
+ changed fails, with the disposition put back.
+ """
+ launch = sys.modules.get("launch")
+ if launch is not None and hasattr(launch, "_install_release_handlers"):
+ monkeypatch.setattr(launch, "_install_release_handlers", lambda release: None)
+ before = {sig: signal.getsignal(sig) for sig in _RELEASE_SIGNALS}
+ yield
+ changed = [sig.name for sig in _RELEASE_SIGNALS if signal.getsignal(sig) is not before[sig]]
+ for sig in _RELEASE_SIGNALS:
+ # None: a handler not set from Python, which signal.signal cannot reinstall.
+ if before[sig] is not None:
+ signal.signal(sig, before[sig])
+ assert not changed, f"the test left process-wide handlers installed for {changed}"
diff --git a/tests/test_decision_gguf.py b/tests/test_decision_gguf.py
index 13fb7f84b62..3b2c8c2e342 100644
--- a/tests/test_decision_gguf.py
+++ b/tests/test_decision_gguf.py
@@ -660,13 +660,20 @@ def test_a_failed_publish_keeps_the_export_of_the_same_weights(
assert contract.read_export(folder) is None
+def default_sigterm():
+ """The SIGTERM disposition is per process, and a pytest worker has run other suites first. A skip
+ read at collection cannot see a handler a later test leaves behind, and the export rightly defers
+ to one, so the SIGTERM sent below then reaches that handler and can take the worker with it."""
+ previous = signal.signal(signal.SIGTERM, signal.SIG_DFL)
+ yield
+ signal.signal(signal.SIGTERM, previous)
+
+
@needs_gguf
- not hasattr(signal, "SIGKILL") or signal.getsignal(signal.SIGTERM) is not signal.SIG_DFL,
- reason = "POSIX signals with the default SIGTERM handler",
-)
[email protected](not hasattr(signal, "SIGKILL"), reason = "POSIX signals")
def test_sigterm_cleans_up_and_a_killed_export_is_swept_later(
- tmp_path, fake_llama_cpp, monkeypatch
+ tmp_path, fake_llama_cpp, monkeypatch, default_sigterm
):
folder = _clef_folder(tmp_path / "run", ("Qwen3_5ForCausalLM",))
convert = decision_gguf._convert