@@ -110,9 +110,17 @@ def get_mem(device_folder: str) -> Optional[int]:
110
110
mem_info_vram_used = os .path .join (device_folder , GPU_MEM_USED )
111
111
if os .path .isfile (mem_info_vram_total ) and os .path .isfile (mem_info_vram_used ):
112
112
with open (mem_info_vram_total ) as f :
113
- mem_info_vram_total = int (f .read ())
113
+ try :
114
+ mem_info_vram_total = int (f .read ())
115
+ except PermissionError :
116
+ # Catch exception (see issue #3125)
117
+ return None
114
118
with open (mem_info_vram_used ) as f :
115
- mem_info_vram_used = int (f .read ())
119
+ try :
120
+ mem_info_vram_used = int (f .read ())
121
+ except PermissionError :
122
+ # Catch exception (see issue #3125)
123
+ return None
116
124
if mem_info_vram_total > 0 :
117
125
return round (mem_info_vram_used / mem_info_vram_total * 100 )
118
126
return None
@@ -123,7 +131,11 @@ def get_proc(device_folder: str) -> Optional[int]:
123
131
gpu_busy_percent = os .path .join (device_folder , GPU_PROC_PERCENT )
124
132
if os .path .isfile (gpu_busy_percent ):
125
133
with open (gpu_busy_percent ) as f :
126
- return int (f .read ())
134
+ try :
135
+ return int (f .read ())
136
+ except PermissionError :
137
+ # Catch exception (see issue #3125)
138
+ return None
127
139
return None
128
140
129
141
@@ -137,7 +149,11 @@ def get_temperature(device_folder: str) -> Optional[int]:
137
149
for f in files :
138
150
if re .match (GPU_TEMPERATURE_REGEXP , f ):
139
151
with open (os .path .join (root , d , f )) as f :
140
- temp_input .append (int (f .read ()))
152
+ try :
153
+ temp_input .append (int (f .read ()))
154
+ except PermissionError :
155
+ # Catch exception (see issue #3125)
156
+ return None
141
157
if temp_input :
142
158
return round (sum (temp_input ) / len (temp_input ) / 1000 )
143
159
return None
0 commit comments