[GH-ISSUE #212] [BUG] Device methods not throwing exceptions #118

Open
opened 2026-05-05 03:26:11 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @lancylot2004 on GitHub (May 2, 2026).
Original GitHub issue: https://github.com/XuehaiPan/nvitop/issues/212

Originally assigned to: @XuehaiPan on GitHub.

Required prerequisites

  • I have read the documentation https://nvitop.readthedocs.io.
  • I have searched the Issue Tracker that this hasn't already been reported. (comment there if it has.)
  • I have tried the latest version of nvitop in a new isolated virtual environment.

What version of nvitop are you using?

1.6.2

Operating system and version

Rocky Linux 9.5 (Blue Onyx) / macOS Tahoe 26.4

Problem description

Device.from_indices (and therefore Device.all) promises to throw exceptions such as NVMLError_LibraryNotFound but actually swallows all. I'd expect NVML related exceptions to be surfaced.

Steps to Reproduce

The Python snippets (if any):

>>> from nvitop import Device
>>> from nvitop.libnvml import NVMLError
>>> try:
...     Device.from_indices()
... except NVMLError as e:
...     print(f"Thrown: {e}")
...     
FATAL ERROR: NVIDIA Management Library (NVML) not found.
HINT: The NVIDIA Management Library ships with the NVIDIA display driver (available at
      https://www.nvidia.com/Download/index.aspx), or can be downloaded as part of the
      NVIDIA CUDA Toolkit (available at https://developer.nvidia.com/cuda-downloads).
      The lists of OS platforms and NVIDIA-GPUs supported by the NVML library can be
      found in the NVML API Reference at https://docs.nvidia.com/deploy/nvml-api.
[]
Originally created by @lancylot2004 on GitHub (May 2, 2026). Original GitHub issue: https://github.com/XuehaiPan/nvitop/issues/212 Originally assigned to: @XuehaiPan on GitHub. ### Required prerequisites - [x] I have read the documentation <https://nvitop.readthedocs.io>. - [x] I have searched the [Issue Tracker](https://github.com/XuehaiPan/nvitop/issues) that this hasn't already been reported. (comment there if it has.) - [x] I have tried the latest version of nvitop in a new isolated virtual environment. ### What version of nvitop are you using? 1.6.2 ### Operating system and version Rocky Linux 9.5 (Blue Onyx) / macOS Tahoe 26.4 ### Problem description `Device.from_indices` (and therefore `Device.all`) promises to throw exceptions such as `NVMLError_LibraryNotFound` but actually swallows all. I'd expect NVML related exceptions to be surfaced. ### Steps to Reproduce The Python snippets (if any): ```python >>> from nvitop import Device >>> from nvitop.libnvml import NVMLError >>> try: ... Device.from_indices() ... except NVMLError as e: ... print(f"Thrown: {e}") ... FATAL ERROR: NVIDIA Management Library (NVML) not found. HINT: The NVIDIA Management Library ships with the NVIDIA display driver (available at https://www.nvidia.com/Download/index.aspx), or can be downloaded as part of the NVIDIA CUDA Toolkit (available at https://developer.nvidia.com/cuda-downloads). The lists of OS platforms and NVIDIA-GPUs supported by the NVML library can be found in the NVML API Reference at https://docs.nvidia.com/deploy/nvml-api. [] ```
gitea-mirror added the
api
bug
labels 2026-05-05 03:26:11 -06:00
Author
Owner

@XuehaiPan commented on GitHub (May 2, 2026):

Hi @lancylot2004, I think it is intentional. The exception is catched in Device.from_indices() (no indices argument is passed):

2f68dd269d/nvitop/api/device.py (L463-L467)

If you pass the indices argument to the method, it will raise the NVMLError_LibraryNotFound exception:

Device.from_indices([0])

The better way is to use Device.is_available() method:

2f68dd269d/nvitop/api/device.py (L331-L337)

Or Device.count() like the CLI does:

2f68dd269d/nvitop/cli.py (L299-L308)

<!-- gh-comment-id:4363752006 --> @XuehaiPan commented on GitHub (May 2, 2026): Hi @lancylot2004, I think it is intentional. The exception is catched in `Device.from_indices()` (no `indices` argument is passed): https://github.com/XuehaiPan/nvitop/blob/2f68dd269d37771f26690701ad5e9d3d83c20d9f/nvitop/api/device.py#L463-L467 If you pass the `indices` argument to the method, it will raise the `NVMLError_LibraryNotFound` exception: ```python Device.from_indices([0]) ``` The better way is to use `Device.is_available()` method: https://github.com/XuehaiPan/nvitop/blob/2f68dd269d37771f26690701ad5e9d3d83c20d9f/nvitop/api/device.py#L331-L337 Or `Device.count()` like the CLI does: https://github.com/XuehaiPan/nvitop/blob/2f68dd269d37771f26690701ad5e9d3d83c20d9f/nvitop/cli.py#L299-L308
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/nvitop#118
No description provided.