FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix child process kill error with npx based servers by surya-prakash-susarla · Pull Request #850 · modelcontextprotocol/python-sdk · GitHub

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 9 additions & 1 deletion src/mcp/client/stdio/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import signal
import sys
from contextlib import asynccontextmanager
from pathlib import Path
Expand Down Expand Up @@ -190,6 +191,13 @@ async def stdin_writer():
await terminate_windows_process(process)
else:
process.terminate()

try:
with anyio.fail_after(5):
await process.wait()
except TimeoutError:
pgid = os.getpgid(process.pid)
os.killpg(pgid, signal.SIGKILL)
except ProcessLookupError:
# Process already exited, which is fine
pass
Expand Down Expand Up @@ -230,7 +238,7 @@ async def _create_platform_compatible_process(
process = await create_windows_process(command, args, env, errlog, cwd)
else:
process = await anyio.open_process(
[command, *args], env=env, stderr=errlog, cwd=cwd
[command, *args], env=env, stderr=errlog, cwd=cwd, start_new_session=True
)

return process

Back | FazBrowse Home | New Git URL