Fix #416 : Prevent nvmlShutdown from being called when uninitialized #417
+4
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #416 : Prevent nvmlShutdown from being called when uninitialized
Problem:
check_nvidia_gpu()
crashes withpynvml.NVMLError_Uninitialized
if NVIDIA GPU is not detected or drivers are missing. This happens becausepynvml.nvmlShutdown()
is called in thefinally
block even ifpynvml.nvmlInit()
failed.Cause:
pynvml.nvmlShutdown()
must only be called after successfulpynvml.nvmlInit()
. WhennvmlInit()
fails, the library is uninitialized, and callingnvmlShutdown()
leads to the error. Thefinally
block unconditionally executesnvmlShutdown()
.Solution:
Introduce an
initialized
flag. Set it toTrue
after successfulpynvml.nvmlInit()
. Conditionally callpynvml.nvmlShutdown()
in thefinally
block only wheninitialized
isTrue
.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.