Avoid importing pynvml if NVML_LIB is not installed

This commit is contained in:
Nicolas Hennion 2024-10-31 16:09:59 +00:00
parent a6956bf7ee
commit 49d15b20da

View File

@ -11,11 +11,20 @@
from glances.globals import nativestr
from glances.logger import logger
NVML_LIB = 'libnvidia-ml.so.1'
try:
# Avoid importing pynvml if NVML_LIB is not installed
from ctypes import CDLL
CDLL(NVML_LIB)
import pynvml
except OSError as e:
nvidia_gpu_enable = False
# NNVML_LIB lib not found (NVidia driver not installed)
logger.warning(f"NVML Shared Library ({NVML_LIB}) not Found, Nvidia GPU plugin is disabled")
except Exception as e:
nvidia_gpu_enable = False
# Display debug message if import KeyError
# Display warning message if import KeyError
logger.warning(f"Missing Python Lib ({e}), Nvidia GPU plugin is disabled")
else:
nvidia_gpu_enable = True