Fix hanging on streams when stdio_client exiting (#559)
This commit is contained in:
parent
37b54b4c03
commit
c5782129bc
2 changed files with 9 additions and 0 deletions
|
|
@ -181,6 +181,8 @@ async def stdio_client(server: StdioServerParameters, errlog: TextIO = sys.stder
|
||||||
await terminate_windows_process(process)
|
await terminate_windows_process(process)
|
||||||
else:
|
else:
|
||||||
process.terminate()
|
process.terminate()
|
||||||
|
await read_stream.aclose()
|
||||||
|
await write_stream.aclose()
|
||||||
|
|
||||||
|
|
||||||
def _get_executable_command(command: str) -> str:
|
def _get_executable_command(command: str) -> str:
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,13 @@ from mcp.types import JSONRPCMessage, JSONRPCRequest, JSONRPCResponse
|
||||||
tee: str = shutil.which("tee") # type: ignore
|
tee: str = shutil.which("tee") # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
@pytest.mark.skipif(tee is None, reason="could not find tee command")
|
||||||
|
async def test_stdio_context_manager_exiting():
|
||||||
|
async with stdio_client(StdioServerParameters(command=tee)) as (_, _):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
@pytest.mark.skipif(tee is None, reason="could not find tee command")
|
@pytest.mark.skipif(tee is None, reason="could not find tee command")
|
||||||
async def test_stdio_client():
|
async def test_stdio_client():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue