Skip to content

Commit c7221f3

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 c7221f3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
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)

0 commit comments

Comments
 (0)