Skip to content

Commit 9e38ab5

Browse files
committed
added 6a703a4 closing file handles in __aexit__ in DummyProcess - Fix ResourceWarning by properly closing file handles in DummyProcess
1 parent dddff2b commit 9e38ab5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/mcp/client/stdio/win32.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ async def __aexit__(
7878
"""Terminate and wait on process exit inside a thread."""
7979
self.popen.terminate()
8080
await to_thread.run_sync(self.popen.wait)
81+
82+
# Close the file handles to prevent ResourceWarning
83+
if self.stdin:
84+
await self.stdin.aclose()
85+
if self.stdout:
86+
await self.stdout.aclose()
87+
if self.stdin_raw:
88+
self.stdin_raw.close()
89+
if self.stdout_raw:
90+
self.stdout_raw.close()
91+
if self.stderr:
92+
self.stderr.close()
8193

8294
async def wait(self):
8395
"""Async wait for process completion."""

0 commit comments

Comments
 (0)