Skip to content

Commit 0f52e75

Browse files
committed
fix: graceful cleanup
1 parent 7ccae4b commit 0f52e75

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-mcp"
3-
version = "0.0.59"
3+
version = "0.0.60"
44
description = "UiPath MCP SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"

src/uipath_mcp/_cli/_runtime/_stdio_client.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,32 @@ async def stdin_writer():
9898
finally:
9999
# Clean up process to prevent any dangling orphaned processes
100100
try:
101+
# Cancel the task group to stop readers/writers
102+
tg.cancel_scope.cancel()
103+
# Close the pipes explicitly to prevent ResourceWarnings
104+
if hasattr(process, "stdin") and process.stdin:
105+
process.stdin.close()
106+
if hasattr(process, "stdout") and process.stdout:
107+
process.stdout.close()
108+
if hasattr(process, "stderr") and process.stderr:
109+
process.stderr.close()
110+
# Then terminate the process with escalating signals
101111
process.terminate()
102-
with anyio.fail_after(2.0):
103-
await process.wait()
104-
except TimeoutError:
105112
try:
106-
if sys.platform == "win32":
107-
# On Windows, simulate Ctrl+C
108-
process.send_signal(signal.CTRL_C_EVENT)
109-
else:
110-
process.send_signal(signal.SIGINT)
111113
with anyio.fail_after(2.0):
112114
await process.wait()
113115
except TimeoutError:
114-
# Force kill if it doesn't terminate
115-
process.kill()
116+
try:
117+
if sys.platform == "win32":
118+
process.send_signal(signal.CTRL_C_EVENT)
119+
else:
120+
process.send_signal(signal.SIGINT)
121+
with anyio.fail_after(2.0):
122+
await process.wait()
123+
except TimeoutError:
124+
# Force kill if it doesn't terminate
125+
process.kill()
126+
# Give the event loop a chance to clean up
127+
await anyio.sleep(0.1)
128+
except Exception:
129+
pass

0 commit comments

Comments
 (0)