]> git.ipfire.org Git - collecty.git/blobdiff - src/collecty/plugins/memory.py
Open all files in a with statement block
[collecty.git] / src / collecty / plugins / memory.py
index 01e4d66489e31de6abbd135462bca2789287ac5d..82791f6e65f661d395b80db2722290f2f613daf0 100644 (file)
@@ -90,11 +90,8 @@ class MemoryObject(base.Object):
                return "default"
 
        def collect(self):
-               f = None
-
-               try:
-                       f = open("/proc/meminfo")
-                       for line in f.readlines():
+               with open("/proc/meminfo") as f:
+                       for line in f:
                                if line.startswith("MemTotal:"):
                                        total = float(line.split()[1])
                                if line.startswith("MemFree:"):
@@ -121,9 +118,6 @@ class MemoryObject(base.Object):
                                ret.append("0")
 
                        return ret
-               finally:
-                       if f:
-                               f.close()
 
 
 class MemoryPlugin(base.Plugin):