Skip to content

Commit 27cf296

Browse files
test
1 parent 08808f3 commit 27cf296

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/mcp/client/stdio/win32.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,32 @@ async def __aexit__(
8080
await to_thread.run_sync(self.popen.wait)
8181

8282
# Close the file handles to prevent ResourceWarning
83+
# Handle already-closed streams gracefully
8384
if self.stdin:
84-
await self.stdin.aclose()
85+
try:
86+
await self.stdin.aclose()
87+
except Exception:
88+
pass # Already closed
8589
if self.stdout:
86-
await self.stdout.aclose()
90+
try:
91+
await self.stdout.aclose()
92+
except Exception:
93+
pass # Already closed
8794
if self.stdin_raw:
88-
self.stdin_raw.close()
95+
try:
96+
self.stdin_raw.close()
97+
except Exception:
98+
pass # Already closed
8999
if self.stdout_raw:
90-
self.stdout_raw.close()
100+
try:
101+
self.stdout_raw.close()
102+
except Exception:
103+
pass # Already closed
91104
if self.stderr:
92-
self.stderr.close()
105+
try:
106+
self.stderr.close()
107+
except Exception:
108+
pass # Already closed
93109

94110
async def wait(self):
95111
"""Async wait for process completion."""

0 commit comments

Comments
 (0)