Skip to content

Commit 0554fe0

Browse files
committed
Add returncode property to FallbackProcess; simplify returncode guard
FallbackProcess stands in for anyio.abc.Process on Windows with SelectorEventLoop, but was missing the returncode property that Process declares abstractly. This meant getattr(proc, "returncode", None) in _terminate_and_reap always returned the default None for FallbackProcess, so the double-terminate guard never fired (the docstring's 'Idempotent' claim was false for half the declared union type). Practical impact was near-zero — FallbackProcess is only active under SelectorEventLoop (not the default since Python 3.8, not used in CI), and terminate_windows_process_tree swallows all exceptions on the second call. But the fix is trivial and brings FallbackProcess closer to the interface it's supposed to implement. With returncode present on both union members, the getattr can become a direct attribute access, which also satisfies pyright without defensive indirection. Github-Issue: #1775
1 parent d8c7de2 commit 0554fe0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/mcp/os/win32/utilities.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def pid(self) -> int:
123123
"""Return the process ID."""
124124
return self.popen.pid
125125

126+
@property
127+
def returncode(self) -> int | None:
128+
"""Return the exit code, or ``None`` if the process has not yet terminated."""
129+
return self.popen.returncode
130+
126131

127132
# ------------------------
128133
# Updated function

tests/client/test_stdio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ async def _terminate_and_reap(proc: anyio.abc.Process | FallbackProcess) -> None
335335
safety net. Bounded by ``move_on_after`` to prevent hangs.
336336
"""
337337
with anyio.move_on_after(5.0):
338-
if getattr(proc, "returncode", None) is None:
338+
if proc.returncode is None:
339339
await _terminate_process_tree(proc)
340340
await proc.wait()
341341
assert proc.stdin is not None

0 commit comments

Comments
 (0)