Skip to content

Commit 08e576a

Browse files
Skip process tree tests on Windows and document limitation
The child process cleanup tests require proper process tree termination, which on Windows needs the Job Objects API. The current implementation using taskkill /T only works for direct children in the same console process group, not for arbitrarily nested process trees. Changes: - Skip the three process tree tests on Windows - Document the limitation in the termination function - Tests still run on Unix platforms where process groups work correctly This is a known limitation that would require significant additional Windows-specific code (Job Objects API) to resolve properly. Reported-by: fweinberger
1 parent 1fc0a25 commit 08e576a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/mcp/client/stdio/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ async def _terminate_process_with_children(process: Process | FallbackProcess, t
307307
await process.wait()
308308
except TimeoutError:
309309
# Force kill using taskkill for tree termination
310+
# Note: This only kills direct children, not grandchildren unless they're
311+
# in the same console process group. Full process tree termination on
312+
# Windows requires Job Objects API.
310313
await anyio.to_thread.run_sync(
311314
subprocess.run,
312315
["taskkill", "/F", "/T", "/PID", str(pid)],

tests/client/test_stdio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ def sigterm_handler(signum, frame):
364364

365365

366366
@pytest.mark.anyio
367+
@pytest.mark.skipif(sys.platform == "win32", reason="Windows process tree termination requires Job Objects API")
367368
async def test_stdio_client_child_process_cleanup():
368369
"""
369370
Test that child processes are properly terminated when the parent is killed.
@@ -468,6 +469,7 @@ async def test_stdio_client_child_process_cleanup():
468469

469470

470471
@pytest.mark.anyio
472+
@pytest.mark.skipif(sys.platform == "win32", reason="Windows process tree termination requires Job Objects API")
471473
async def test_stdio_client_nested_process_tree():
472474
"""
473475
Test that a nested process tree (parent → child → grandchild) is properly cleaned up.
@@ -575,6 +577,7 @@ async def test_stdio_client_nested_process_tree():
575577

576578

577579
@pytest.mark.anyio
580+
@pytest.mark.skipif(sys.platform == "win32", reason="Windows process tree termination requires Job Objects API")
578581
async def test_stdio_client_early_parent_exit():
579582
"""
580583
Test that child processes are cleaned up when parent exits during cleanup.

0 commit comments

Comments
 (0)