MCPcopy
hub / github.com/modelcontextprotocol/python-sdk / _drain_stdout

Function _drain_stdout

src/mcp/client/stdio.py:228–245  ·  view source on GitHub ↗

Consumes and discards the server's remaining stdout. Keeps a server flushing buffered output from blocking on a full pipe and missing its chance to exit; shielded, raw bytes, ends when shutdown closes the pipe.

(process: ServerProcess)

Source from the content-addressed store, hash-verified

226
227
228async def _drain_stdout(process: ServerProcess) -> None:
229 """Consumes and discards the server's remaining stdout.
230
231 Keeps a server flushing buffered output from blocking on a full pipe and
232 missing its chance to exit; shielded, raw bytes, ends when shutdown closes
233 the pipe.
234 """
235 assert process.stdout
236 with anyio.CancelScope(shield=True):
237 with suppress(
238 anyio.EndOfStream,
239 anyio.ClosedResourceError,
240 anyio.BrokenResourceError,
241 ConnectionError,
242 OSError,
243 ):
244 while True:
245 await process.stdout.receive()
246
247
248async def _stop_server_process(process: ServerProcess) -> None:

Callers 1

stdout_readerFunction · 0.85

Calls 1

receiveMethod · 0.45

Tested by

no test coverage detected