Skip to content

Commit ac874df

Browse files
rustyconoverclaude
andcommitted
Release 0.54.1: idle exit on Windows
On Windows os.kill(pid, 0) is CTRL_C_EVENT, so the granian child liveness probe interrupted every process on the console (pytest died with KeyboardInterrupt on the Windows CI lanes). Probe with OpenProcess + GetExitCodeProcess instead. Granian's idle exit stops the parent with SIGTERM, which Windows can only deliver as TerminateProcess (exit 15), so VGI_IDLE_EXIT_SECONDS with --server granian is refused on Windows; waitress works everywhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e3bbf8b commit ac874df

6 files changed

Lines changed: 44 additions & 5 deletions

File tree

‎packages/vgi-fixtures/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# and the conformance suite import it by its normal `vgi._test_fixtures` path.
99
[project]
1010
name = "vgi-fixtures"
11-
version = "0.54.0"
11+
version = "0.54.1"
1212
description = "Example/test VGI worker modules and entry points (not for production use)"
1313
readme = "README.md"
1414
# Local copy of the repo-root LICENSE (kept in sync): the build can't reach

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "vgi-python"
3-
version = "0.54.0"
3+
version = "0.54.1"
44
description = "Vector Gateway Interface - Connect DuckDB to external programs via Apache Arrow"
55
readme = "README.md"
66
keywords = [

‎tests/test_idle_exit.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,22 @@ def _get(port: int, path: str, method: str = "GET") -> int:
287287
pytest.param(
288288
("--server", "granian", "--http-workers", "2"),
289289
id="granian",
290-
marks=pytest.mark.skipif(importlib.util.find_spec("granian") is None, reason="granian extra not installed"),
290+
marks=[
291+
pytest.mark.skipif(importlib.util.find_spec("granian") is None, reason="granian extra not installed"),
292+
pytest.mark.skipif(sys.platform == "win32", reason="granian idle exit is refused on Windows"),
293+
],
291294
),
292295
]
293296

294297

298+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows only")
299+
def test_pid_alive_does_not_signal_on_windows() -> None:
300+
"""The liveness probe never sends CTRL_C_EVENT (signal 0) to the console."""
301+
assert idle_exit._pid_alive(os.getpid())
302+
proc = subprocess.run([sys.executable, "-c", "import os; print(os.getpid())"], capture_output=True, text=True)
303+
assert not idle_exit._pid_alive(int(proc.stdout.strip()))
304+
305+
295306
@pytest.mark.parametrize("extra", _SERVERS)
296307
def test_serve_exits_cleanly_when_idle(extra: tuple[str, ...]) -> None:
297308
"""Requests keep the server up; health checks don't; quiet for the period exits 0."""

‎uv.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vgi/idle_exit.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import logging
3939
import os
4040
import signal
41+
import sys
4142
import threading
4243
import time
4344
from collections.abc import Callable, Iterable, Iterator
@@ -219,6 +220,8 @@ def __call__(self, environ: dict[str, Any], start_response: Callable[..., Any])
219220

220221

221222
def _pid_alive(pid: int) -> bool:
223+
if sys.platform == "win32":
224+
return _pid_alive_windows(pid)
222225
try:
223226
os.kill(pid, 0)
224227
except ProcessLookupError:
@@ -228,6 +231,27 @@ def _pid_alive(pid: int) -> bool:
228231
return True
229232

230233

234+
def _pid_alive_windows(pid: int) -> bool: # pragma: no cover - Windows only
235+
# Not os.kill(pid, 0): on Windows signal 0 is CTRL_C_EVENT, which interrupts
236+
# every process on the console instead of probing one.
237+
import ctypes
238+
239+
process_query_limited_information = 0x1000
240+
still_active = 259
241+
kernel32 = ctypes.windll.kernel32 # type: ignore[attr-defined,unused-ignore]
242+
handle = kernel32.OpenProcess(process_query_limited_information, False, pid)
243+
if not handle:
244+
# Access denied means it exists; anything else (invalid parameter) means gone.
245+
return bool(kernel32.GetLastError() == 5)
246+
try:
247+
code = ctypes.c_ulong()
248+
if not kernel32.GetExitCodeProcess(handle, ctypes.byref(code)):
249+
return True
250+
return code.value == still_active
251+
finally:
252+
kernel32.CloseHandle(handle)
253+
254+
231255
class DirectoryActivity:
232256
"""Aggregate the per-process state files granian children write."""
233257

‎vgi/serve.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,10 @@ def _serve_http_granian(
15381538
sys.stderr.write(f"Serving {worker_cls.__name__} on http://{host}:{port}{prefix} (granian, {workers} worker(s))\n")
15391539
sys.stderr.flush()
15401540

1541+
if idle_exit_seconds is not None and sys.platform == "win32":
1542+
# The parent stops granian with SIGTERM, which Windows can only deliver as
1543+
# TerminateProcess: a hard kill with exit status 15, not a clean exit.
1544+
raise SystemExit("VGI_IDLE_EXIT_SECONDS is not supported with --server granian on Windows; use waitress")
15411545
server = Granian(
15421546
"vgi.serve:wsgi_app_factory",
15431547
address=host,

0 commit comments

Comments
 (0)