Skip to content

Commit 017974a

Browse files
committed
fix: replace Unix kill commands with cross-platform os.kill in ChromaDB provisioner
The provisioner used subprocess calls to the Unix `kill` command for process management, which doesn't exist on Windows. Replace with os.kill() which works cross-platform.
1 parent cda1929 commit 017974a

1 file changed

Lines changed: 16 additions & 27 deletions

File tree

backend/syft_space/components/dataset_types/chromadb_local/chromadb_provisioner.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""ChromaDB provisioner implementation."""
22

33
import asyncio
4+
import os
5+
import signal
46
import sys
57
import time
68
from typing import Any
@@ -159,33 +161,24 @@ async def stop(cls, state: dict[str, Any]) -> None:
159161

160162
if pid:
161163
try:
162-
# SIGTERM for graceful shutdown (async-safe via subprocess)
163-
proc = await asyncio.create_subprocess_exec(
164-
"kill",
165-
"-TERM",
166-
str(pid),
167-
stdout=asyncio.subprocess.DEVNULL,
168-
stderr=asyncio.subprocess.DEVNULL,
169-
)
170-
await proc.wait()
164+
# Graceful shutdown: SIGTERM on Unix, CTRL_BREAK on Windows
165+
if sys.platform == "win32":
166+
os.kill(pid, signal.CTRL_BREAK_EVENT)
167+
else:
168+
os.kill(pid, signal.SIGTERM)
171169

172170
# Wait for graceful shutdown
173171
await asyncio.sleep(2.0)
174172

175173
# Check if still running, force kill if needed
176174
if await cls._is_process_running(pid):
177-
kill_proc = await asyncio.create_subprocess_exec(
178-
"kill",
179-
"-KILL",
180-
str(pid),
181-
stdout=asyncio.subprocess.DEVNULL,
182-
stderr=asyncio.subprocess.DEVNULL,
183-
)
184-
await kill_proc.wait()
175+
os.kill(pid, signal.SIGKILL if sys.platform != "win32" else signal.SIGTERM)
185176
logger.info(f"Force killed ChromaDB process {pid}")
186177
else:
187178
logger.info(f"ChromaDB process {pid} stopped gracefully")
188179

180+
except (OSError, ProcessLookupError):
181+
logger.info(f"ChromaDB process {pid} already stopped")
189182
except Exception as e:
190183
logger.warning(f"Error stopping ChromaDB process {pid}: {e}")
191184

@@ -237,23 +230,19 @@ async def status(cls, state: dict[str, Any]) -> str:
237230

238231
@classmethod
239232
async def _is_process_running(cls, pid: int) -> bool:
240-
"""Check if a process is running (async-safe).
233+
"""Check if a process is running.
241234
242235
Args:
243236
pid: Process ID to check
244237
245238
Returns:
246239
True if process exists, False otherwise
247240
"""
248-
proc = await asyncio.create_subprocess_exec(
249-
"kill",
250-
"-0",
251-
str(pid),
252-
stdout=asyncio.subprocess.DEVNULL,
253-
stderr=asyncio.subprocess.DEVNULL,
254-
)
255-
await proc.wait()
256-
return proc.returncode == 0
241+
try:
242+
os.kill(pid, 0)
243+
return True
244+
except (OSError, ProcessLookupError):
245+
return False
257246

258247
@classmethod
259248
async def _wait_for_healthy(cls, http_port: int, timeout: float = 60.0) -> None:

0 commit comments

Comments
 (0)