nv-generate / utils /logging_setup.py
nv-mzephyr's picture
Claude Opus 5 (1M context)
Stream volumes by URL, cache checkpoints, reclaim archive space, quiet logs
f265752
Raw History Blame Contribute Delete
2.13 kB
"""Quiet the container logs down to signal.
The Space logs were dominated by three sources of noise that bury the lines
that actually matter (phase timings, the READY banner, real errors):
* `Exception ignored in: <function BaseEventLoop.__del__>` with
`ValueError: Invalid file descriptor: -1`, twice per boot. This is the
garbage collector finalising an event loop that is already closed, during
Gradio's SSR startup. Python prints it via the unraisable hook and then
discards it -- it is unreachable by try/except and affects nothing.
* `StarletteDeprecationWarning: 'HTTP_422_UNPROCESSABLE_ENTITY' is
deprecated`, emitted by Gradio on essentially every queue join.
* A MONAI `FutureWarning` about `Orientationd(labels=...)` on every run.
Each is suppressed narrowly, by exact type and message, so an unrelated
ValueError or a different deprecation still surfaces.
"""
from __future__ import annotations
import os
import sys
import warnings
_original_unraisablehook = sys.unraisablehook
def _quiet_unraisable(unraisable):
"""Drop only the closed-event-loop finaliser noise; forward everything else."""
exc = unraisable.exc_value
if (
isinstance(exc, ValueError)
and "Invalid file descriptor" in str(exc)
and getattr(unraisable.object, "__qualname__", "").endswith("BaseEventLoop.__del__")
):
return
_original_unraisablehook(unraisable)
def configure() -> None:
"""Install the log filters. Safe to call once, early, before Gradio imports."""
sys.unraisablehook = _quiet_unraisable
warnings.filterwarnings(
"ignore",
message=r".*HTTP_422_UNPROCESSABLE_ENTITY.*",
)
warnings.filterwarnings(
"ignore",
category=FutureWarning,
module=r"monai\..*",
message=r".*Orientationd.*",
)
# hf_hub progress bars produce dozens of carriage-return lines per file and
# are redundant now that prefetch reports a duration per model. Only set the
# default: an explicit value in the Space environment still wins.
os.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1")