Skip to content

Commit 4e8e4e8

Browse files
Fix Windows: Use taskkill /T directly without graceful termination
On Windows, process.terminate() only kills the parent process, not children. By the time we timeout and call taskkill /T, the parent is already dead and child processes might not be properly associated. Instead, directly use taskkill /T on Windows to kill the entire process tree in one operation. This matches what the debug scripts showed - taskkill /T works when called directly on a live parent.
1 parent 791b6dd commit 4e8e4e8

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/mcp/client/stdio/__init__.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,6 @@ async def _terminate_process_with_children(process: Process | FallbackProcess, t
326326
if not pid:
327327
return
328328

329-
# Try graceful termination first
330-
try:
331-
process.terminate()
332-
with anyio.fail_after(timeout):
333-
await process.wait()
334-
except TimeoutError:
335-
# On Windows, we need to recursively kill all child processes
336-
# because taskkill /T doesn't always work with Python subprocesses
337-
await _kill_process_tree_windows(pid)
338-
except ProcessLookupError:
339-
pass
329+
# On Windows, directly use taskkill /T to kill the entire process tree
330+
# Don't try graceful termination first as it only kills the parent
331+
await _kill_process_tree_windows(pid)

0 commit comments

Comments
 (0)