Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

If the gpu stats command fails, don't run it again on every usage check (#6202)

loginoff70c2815be9c6
diff --git a/marimo/_server/api/endpoints/health.py b/marimo/_server/api/endpoints/health.py
index 006e12a625..b618a50f5b 100644
--- a/marimo/_server/api/endpoints/health.py
+++ b/marimo/_server/api/endpoints/health.py
@@ -232,11 +232,7 @@ async def usage(request: Request) -> JSONResponse:
if _is_gpu_available():
try:
result = subprocess.run( # noqa: ASYNC221
- [
- "nvidia-smi",
- "--query-gpu=index,name,memory.total,memory.used,memory.free",
- "--format=csv,noheader,nounits",
- ],
+ _GPU_STATS_CMD,
capture_output=True,
text=True,
check=True,
@@ -311,6 +307,27 @@ async def connections(request: Request) -> JSONResponse:
)
+_GPU_STATS_CMD = [
+ "nvidia-smi",
+ "--query-gpu=index,name,memory.total,memory.used,memory.free",
+ "--format=csv,noheader,nounits",
+]
+
+
@lru_cache(maxsize=1)
def _is_gpu_available() -> bool:
- return DependencyManager.which("nvidia-smi")
+ import subprocess
+
+ if DependencyManager.which("nvidia-smi"):
+ try:
+ _ = subprocess.run( # noqa: ASYNC221
+ _GPU_STATS_CMD,
+ capture_output=True,
+ text=True,
+ check=True,
+ )
+ return True
+ except (subprocess.SubprocessError, FileNotFoundError) as e:
+ LOGGER.warning("Failed to extract GPU stats: %s", e)
+ return False
+ return False