aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Kacur <jkacur@redhat.com>2022-05-06 19:18:49 -0400
committerJohn Kacur <jkacur@redhat.com>2022-05-06 19:21:29 -0400
commita46f0b622b5aa31741813834b8b97560d0cc2d03 (patch)
tree89cb4bbd05d9a729b7b66fdcf09f6a6a4d0147d0
parent8e224cfd0244fe0578916574c84f7338a6b68e07 (diff)
downloadrteval-a46f0b622b5aa31741813834b8b97560d0cc2d03.tar.gz
rteval: systopology.py: Use "with" for resource allocation
- Use "with" with open Signed-off-by: John Kacur <jkacur@redhat.com>
-rw-r--r--rteval/systopology.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/rteval/systopology.py b/rteval/systopology.py
index b2da7bb..e852f86 100644
--- a/rteval/systopology.py
+++ b/rteval/systopology.py
@@ -180,13 +180,14 @@ class NumaNode:
def getmeminfo(self):
""" read info about memory attached to this node """
self.meminfo = {}
- for l in open(os.path.join(self.path, "meminfo"), "r"):
- elements = l.split()
- key = elements[2][0:-1]
- val = int(elements[3])
- if len(elements) == 5 and elements[4] == "kB":
- val *= 1024
- self.meminfo[key] = val
+ with open(os.path.join(self.path, "meminfo"), "r") as fp:
+ for l in fp:
+ elements = l.split()
+ key = elements[2][0:-1]
+ val = int(elements[3])
+ if len(elements) == 5 and elements[4] == "kB":
+ val *= 1024
+ self.meminfo[key] = val
def getcpustr(self):
""" return list of cpus for this node as a string """
@@ -212,13 +213,14 @@ class SimNumaNode(NumaNode):
def getmeminfo(self):
self.meminfo = {}
- for l in open(SimNumaNode.mempath, "r"):
- elements = l.split()
- key = elements[0][0:-1]
- val = int(elements[1])
- if len(elements) == 3 and elements[2] == "kB":
- val *= 1024
- self.meminfo[key] = val
+ with open(SimNumaNode.mempath, "r") as fp:
+ for l in fp:
+ elements = l.split()
+ key = elements[0][0:-1]
+ val = int(elements[1])
+ if len(elements) == 3 and elements[2] == "kB":
+ val *= 1024
+ self.meminfo[key] = val
#
# Class to abstract the system topology of numa nodes and cpus