Skip to content

Commit ae68a02

Browse files
committed
Fix ResourceWarning: unclosed file in test_cpudemo
1 parent 56a94b5 commit ae68a02

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

qwt/tests/test_cpudemo.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ def upTime(self):
202202

203203
def __lookup(self):
204204
if os.path.exists("/proc/stat"):
205-
for line in open("/proc/stat"):
206-
words = line.split()
207-
if words[0] == "cpu" and len(words) >= 5:
208-
return [float(w) for w in words[1:]]
205+
with open("/proc/stat") as file:
206+
for line in file:
207+
words = line.split()
208+
if words[0] == "cpu" and len(words) >= 5:
209+
return [float(w) for w in words[1:]]
209210
else:
210211
result = CpuStat.dummyValues[CpuStat.counter]
211212
CpuStat.counter += 1

0 commit comments

Comments
 (0)