Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
serve tests: a stopped server stops its hardware sampler (21 samplers leaked after test_responses skewed test_parallel's timing)
Niko1221bad9a8f22e90
diff --git a/serve/server.py b/serve/server.pyindex 0d62e641b..eae539276 100644--- a/serve/server.py+++ b/serve/server.py@@ -5024,6 +5024,14 @@ class Server(ThreadingHTTPServer):if not isinstance(sys.exc_info()[1], ConnectionError): # a client that hangs up needs no stack tracesuper().handle_error(request, client_address)+ def server_close(self):+ # the hardware sampler serve() started for this server stops with it (test isolation: every Service a test+ # started used to leave its sampler running, 21 of them after test_responses, which slowed test_parallel's timing)+ tel = getattr(getattr(self, "svc", None), "telemetry", None)+ if tel is not None and hasattr(tel, "close"):+ tel.close()+ super().server_close()+def warn_tight_ram(arena_mib) -> None:"""The model's experts live in RAM (INFO arena_mib, engine 0.1.10+). With less than ~6 GB left beside them for the@@ -5251,6 +5259,7 @@ def serve(svc: Service, host="127.0.0.1", port=8095) -> ThreadingHTTPServer:svc.host_names = host_names_for(host, svc.allowed_hosts, svc.trusted_origins)svc.start_telemetry()httpd = Server((host, port), make_handler(svc))+ httpd.svc = svcthreading.Thread(target=httpd.serve_forever, daemon=True).start()return httpddiff --git a/serve/telemetry.py b/serve/telemetry.pyindex 33ad71acf..8a629e041 100644--- a/serve/telemetry.py+++ b/serve/telemetry.py@@ -297,6 +297,7 @@ class Telemetry:"psutil": self.ps is not None,}self._disk_prev = None+ self._stop = threading.Event()threading.Thread(target=self._loop, daemon=True).start()def _disk(self):@@ -350,8 +351,12 @@ class Telemetry:passreturn s+ def close(self):+ """Ends the sampler thread (a server that stops, a test's service): it used to run for the life of the process."""+ self._stop.set()+def _loop(self):- while True:+ while not self._stop.is_set():s = self.sample()with self.lock:self.now = s@@ -359,7 +364,7 @@ class Telemetry:"disk_read_mb", "tok_s", "prefill_tok_s_mean"):v = s.get(k)self.hist[k].append(round(v, 2) if isinstance(v, float) else v)- time.sleep(1.0)+ self._stop.wait(1.0)def snapshot(self):with self.lock:diff --git a/serve/test_responses.py b/serve/test_responses.pyindex e2935c489..06c2b39de 100644--- a/serve/test_responses.py+++ b/serve/test_responses.py@@ -271,6 +271,26 @@ class CodexCompaction(unittest.TestCase):self.assertEqual(tools_of(codex_request("compaction", meta=odd)), (None, None)) # not a compaction: as sent+class NoLeakedSampler(unittest.TestCase):+ """Test isolation: a stopped server stops its hardware sampler. Every Service these tests started used to leave one+ running (21 after this file), polling NVML and psutil every second, which skewed serve/test_parallel's timings."""++ def test_server_close_ends_the_sampler(self):+ import threading+ import time+ tok = ByteTokenizer()+ before = sum(1 for t in threading.enumerate() if t.name.endswith("(_loop)"))+ httpd = serve(Service(MockEngine(tok, ANSWER, max_context=16384), tok, TEMPLATE), port=0)+ self.assertEqual(sum(1 for t in threading.enumerate() if t.name.endswith("(_loop)")), before + 1)+ httpd.shutdown()+ httpd.server_close()+ for _ in range(50):+ if sum(1 for t in threading.enumerate() if t.name.endswith("(_loop)")) == before:+ break+ time.sleep(0.1)+ self.assertEqual(sum(1 for t in threading.enumerate() if t.name.endswith("(_loop)")), before)++# ------------------------------------------------------------------------------------------------ over HTTPclass Server(unittest.TestCase):script = ANSWER