Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #416 : Prevent nvmlShutdown from being called when uninitialized #417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Yanlin-Duanmu
Copy link

Fix #416 : Prevent nvmlShutdown from being called when uninitialized

Problem:
check_nvidia_gpu() crashes with pynvml.NVMLError_Uninitialized if NVIDIA GPU is not detected or drivers are missing. This happens because pynvml.nvmlShutdown() is called in the finally block even if pynvml.nvmlInit() failed.

Cause:
pynvml.nvmlShutdown() must only be called after successful pynvml.nvmlInit(). When nvmlInit() fails, the library is uninitialized, and calling nvmlShutdown() leads to the error. The finally block unconditionally executes nvmlShutdown().

Solution:
Introduce an initialized flag. Set it to True after successful pynvml.nvmlInit(). Conditionally call pynvml.nvmlShutdown() in the finally block only when initialized is True.

Impact:
Prevents crash when NVIDIA GPU is not detected or drivers are missing. Improves error handling and robustness.

No new tests needed as it fixes error flow.

…alized

Problem:
`check_nvidia_gpu()` crashes with `pynvml.NVMLError_Uninitialized` if NVIDIA GPU is not detected or drivers are missing. This happens because `pynvml.nvmlShutdown()` is called in the `finally` block even if `pynvml.nvmlInit()` failed.

Cause:
`pynvml.nvmlShutdown()` must only be called after successful `pynvml.nvmlInit()`. When `nvmlInit()` fails, the library is uninitialized, and calling `nvmlShutdown()` leads to the error. The `finally` block unconditionally executes `nvmlShutdown()`.

Solution:
Introduce an `initialized` flag. Set it to `True` after successful `pynvml.nvmlInit()`.  Conditionally call `pynvml.nvmlShutdown()` in the `finally` block only when `initialized` is `True`.

Impact:
Prevents crash when NVIDIA GPU is not detected or drivers are missing. Improves error handling and robustness.

No new tests needed as it fixes error flow.
@Yanlin-Duanmu
Copy link
Author

Yanlin-Duanmu commented Mar 2, 2025

Before:

image

After:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: Crash in install.py: NVMLError_Uninitialized on shutdown when no NVIDIA GPU/drivers present
1 participant