From 6c21ee243d5395957dbdbb33f16483e89244a9c7 Mon Sep 17 00:00:00 2001 From: Rachitt Shah Date: Thu, 5 Mar 2026 19:39:09 +0000 Subject: [PATCH] Add a POSIX sysconf fallback for local RAM detection Retain the unsuperseded macOS RAM-detection contribution from PR #13 while making every optional probe fail closed. The shared MPS device, loader, cache, and dtype work is already present on current main and is intentionally not duplicated. --- obliteratus/local_ui.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/obliteratus/local_ui.py b/obliteratus/local_ui.py index 428b837..c9d950d 100644 --- a/obliteratus/local_ui.py +++ b/obliteratus/local_ui.py @@ -100,16 +100,27 @@ def _get_ram_gb() -> float: import psutil return round(psutil.virtual_memory().total / 1024**3, 1) - except ImportError: - # Fallback: read from /proc/meminfo on Linux - try: - with open("/proc/meminfo") as f: - for line in f: - if line.startswith("MemTotal:"): - kb = int(line.split()[1]) - return round(kb / 1024**2, 1) - except Exception: - pass + except (AttributeError, ImportError, OSError, RuntimeError, ValueError): + pass + + # Fallback: read from /proc/meminfo on Linux. + try: + with open("/proc/meminfo") as f: + for line in f: + if line.startswith("MemTotal:"): + kb = int(line.split()[1]) + return round(kb / 1024**2, 1) + except (OSError, ValueError): + pass + + # macOS and other POSIX systems generally expose physical RAM via sysconf. + try: + pages = os.sysconf("SC_PHYS_PAGES") + page_size = os.sysconf("SC_PAGE_SIZE") + if pages > 0 and page_size > 0: + return round(pages * page_size / 1024**3, 1) + except (AttributeError, OSError, ValueError): + pass return 0.0