close sysfs file

This commit is contained in:
xxyzz 2021-12-16 13:15:21 +08:00
parent c3925db827
commit b37a4b1f7a
No known key found for this signature in database
GPG Key ID: F796163E6DCFEE9D

View File

@ -530,7 +530,8 @@ class Device(DeviceConfig, DevicePlugin):
if not os.access(sz, os.R_OK):
continue
try:
sz = int(open(sz, 'rb').read().decode('utf-8'))
with open(sz, 'rb') as szf:
sz = int(szf.read().decode('utf-8'))
except:
continue
if sz > 0: