From 57c42320ce27e2dc0893f12c8b74e5aad4497c4c Mon Sep 17 00:00:00 2001 From: Sander Jonkers Date: Mon, 27 Apr 2020 20:19:09 +0200 Subject: [PATCH] getcpu(): solves unclosed '/proc/cpuinfo' --- sabnzbd/utils/getperformance.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sabnzbd/utils/getperformance.py b/sabnzbd/utils/getperformance.py index f366adf..583ae2e 100644 --- a/sabnzbd/utils/getperformance.py +++ b/sabnzbd/utils/getperformance.py @@ -22,12 +22,13 @@ def getcpu(): cputype = subprocess.check_output(["sysctl", "-n", "machdep.cpu.brand_string"]).strip() elif platform.system() == "Linux": - for myline in open("/proc/cpuinfo"): - if myline.startswith("model name"): - # Typical line: - # model name : Intel(R) Xeon(R) CPU E5335 @ 2.00GHz - cputype = myline.split(":", 1)[1] # get everything after the first ":" - break # we're done + with open("/proc/cpuinfo") as fp: + for myline in fp.readlines(): + if myline.startswith("model name"): + # Typical line: + # model name : Intel(R) Xeon(R) CPU E5335 @ 2.00GHz + cputype = myline.split(":", 1)[1] # get everything after the first ":" + break # we're done cputype = cputype.decode(locale.getpreferredencoding()) except: # An exception, maybe due to a subprocess call gone wrong