Skip to content

Commit 2ca86f6

Browse files
author
Yoshihiro Takahara
committed
feat: improve process cleanup and test configuration
- Add proper process cleanup in shell_executor - Update pytest-asyncio configuration
1 parent be5bf7e commit 2ca86f6

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/mcp_shell_server/shell_executor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ async def execute(
386386
timeout: Optional[int] = None,
387387
) -> Dict[str, Any]:
388388
start_time = time.time()
389+
process = None # Initialize process variable
389390

390391
try:
391392
# Validate directory if specified
@@ -590,6 +591,11 @@ async def communicate_with_timeout():
590591
"stderr": str(e),
591592
"execution_time": time.time() - start_time,
592593
}
594+
finally:
595+
# Ensure process is terminated
596+
if process and process.returncode is None:
597+
process.kill()
598+
await process.wait()
593599

594600
async def _execute_pipeline(
595601
self,
@@ -692,5 +698,10 @@ async def _execute_pipeline(
692698
}
693699

694700
finally:
701+
# Ensure all processes are terminated
702+
for process in processes:
703+
if process.returncode is None:
704+
process.kill()
705+
await process.wait()
695706
if isinstance(last_stdout, IO):
696707
last_stdout.close()

tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import os
22

3-
43
# Configure pytest-asyncio
54
def pytest_configure(config):
65
"""Configure pytest-asyncio defaults"""
7-
config.option.asyncio_mode = "strict"
86
# Enable command execution for tests
97
os.environ["ALLOW_COMMANDS"] = "1"
108
# Add allowed commands for tests

0 commit comments

Comments
 (0)