Skip to content

Commit 046bed4

Browse files
Use anyio.move_on_after for process group termination timeout
Replace manual deadline checking with anyio.move_on_after context manager for cleaner and more idiomatic timeout handling in Unix process group termination.
1 parent 71bb079 commit 046bed4

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/mcp/client/stdio/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ async def _terminate_process_tree(process: Process | FallbackProcess, timeout: f
265265
pgid = os.getpgid(pid)
266266
os.killpg(pgid, signal.SIGTERM)
267267

268-
deadline = anyio.current_time() + timeout
269-
while anyio.current_time() < deadline:
270-
try:
271-
# Check if process group still exists (signal 0 = check only)
272-
os.killpg(pgid, 0)
273-
await anyio.sleep(0.1)
274-
except ProcessLookupError:
275-
return
268+
with anyio.move_on_after(timeout):
269+
while True:
270+
try:
271+
# Check if process group still exists (signal 0 = check only)
272+
os.killpg(pgid, 0)
273+
await anyio.sleep(0.1)
274+
except ProcessLookupError:
275+
return
276276

277277
try:
278278
os.killpg(pgid, signal.SIGKILL)

src/mcp/client/stdio/win32.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ async def _create_windows_fallback_process(
227227
cwd=cwd,
228228
bufsize=0,
229229
)
230-
process = FallbackProcess(popen_obj)
231-
return process
230+
return FallbackProcess(popen_obj)
232231

233232

234233
def _create_job_object() -> int | None:

0 commit comments

Comments
 (0)