Browse Source

getcpu(): solves unclosed '/proc/cpuinfo'

pull/1407/head
Sander Jonkers 5 years ago
committed by Safihre
parent
commit
57c42320ce
  1. 13
      sabnzbd/utils/getperformance.py

13
sabnzbd/utils/getperformance.py

@ -22,12 +22,13 @@ def getcpu():
cputype = subprocess.check_output(["sysctl", "-n", "machdep.cpu.brand_string"]).strip() cputype = subprocess.check_output(["sysctl", "-n", "machdep.cpu.brand_string"]).strip()
elif platform.system() == "Linux": elif platform.system() == "Linux":
for myline in open("/proc/cpuinfo"): with open("/proc/cpuinfo") as fp:
if myline.startswith("model name"): for myline in fp.readlines():
# Typical line: if myline.startswith("model name"):
# model name : Intel(R) Xeon(R) CPU E5335 @ 2.00GHz # Typical line:
cputype = myline.split(":", 1)[1] # get everything after the first ":" # model name : Intel(R) Xeon(R) CPU E5335 @ 2.00GHz
break # we're done cputype = myline.split(":", 1)[1] # get everything after the first ":"
break # we're done
cputype = cputype.decode(locale.getpreferredencoding()) cputype = cputype.decode(locale.getpreferredencoding())
except: except:
# An exception, maybe due to a subprocess call gone wrong # An exception, maybe due to a subprocess call gone wrong

Loading…
Cancel
Save