Skip to content

Commit 4bcb6c9

Browse files
committed
style: miscellaneous style housekeeping
1 parent 1cff66b commit 4bcb6c9

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

nvitop/api/device.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,14 @@ def receive(self) -> int | NaType:
189189
return self.rx
190190

191191

192-
_VALUE_OMITTED: str = object() # type: ignore[assignment]
192+
# pylint: disable-next=missing-class-docstring,too-few-public-methods
193+
class ValueOmitted:
194+
def __repr__(self) -> str:
195+
return '<VALUE OMITTED>'
196+
197+
198+
_VALUE_OMITTED: str = ValueOmitted() # type: ignore[assignment]
199+
del ValueOmitted
193200

194201

195202
class Device: # pylint: disable=too-many-instance-attributes,too-many-public-methods
@@ -2904,14 +2911,17 @@ class _PhysicalDeviceAttrs(NamedTuple):
29042911
support_mig_mode: bool
29052912

29062913

2907-
_PHYSICAL_DEVICE_ATTRS = None
2908-
_GLOBAL_PHYSICAL_DEVICE = None
2909-
_GLOBAL_PHYSICAL_DEVICE_LOCK = threading.RLock()
2914+
_PHYSICAL_DEVICE_ATTRS: OrderedDict[str, _PhysicalDeviceAttrs] | None = None
2915+
_GLOBAL_PHYSICAL_DEVICE: PhysicalDevice | None = None
2916+
_GLOBAL_PHYSICAL_DEVICE_LOCK: threading.RLock = threading.RLock()
29102917

29112918

2912-
def _get_all_physical_device_attrs() -> dict[str, _PhysicalDeviceAttrs]:
2919+
def _get_all_physical_device_attrs() -> OrderedDict[str, _PhysicalDeviceAttrs]:
29132920
global _PHYSICAL_DEVICE_ATTRS # pylint: disable=global-statement
29142921

2922+
if _PHYSICAL_DEVICE_ATTRS is not None:
2923+
return _PHYSICAL_DEVICE_ATTRS
2924+
29152925
with _GLOBAL_PHYSICAL_DEVICE_LOCK:
29162926
if _PHYSICAL_DEVICE_ATTRS is None:
29172927
_PHYSICAL_DEVICE_ATTRS = OrderedDict(
@@ -3138,10 +3148,7 @@ def _parse_cuda_visible_devices_to_uuids(
31383148
parser.start()
31393149
parser.join()
31403150
finally:
3141-
try:
3142-
parser.kill() # requires Python 3.7+
3143-
except AttributeError:
3144-
pass
3151+
parser.kill()
31453152
result = queue.get()
31463153

31473154
if isinstance(result, Exception):

0 commit comments

Comments
 (0)