summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorSeth Troisi <sethtroisi@google.com>2020-01-21 11:32:58 -0800
committerSeth Troisi <sethtroisi@google.com>2020-01-21 11:34:58 -0800
commitb54108238dbd1ce2673a042b0b270f666ea96e29 (patch)
tree6299fd6681a589e4f7a58f8acd045e2579827d5c /numpy/testing/_private/utils.py
parent19b96a1635ee93c487d69ab88ac5ea3a6a14e79e (diff)
downloadnumpy-b54108238dbd1ce2673a042b0b270f666ea96e29.tar.gz
STY: use `with open` when possible
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index 1b88d91f6..8b098f1d1 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -192,9 +192,8 @@ elif sys.platform[:5] == 'linux':
"""
try:
- f = open(_proc_pid_stat, 'r')
- l = f.readline().split(' ')
- f.close()
+ with open(_proc_pid_stat, 'r') as f:
+ l = f.readline().split(' ')
return int(l[22])
except Exception:
return
@@ -221,9 +220,8 @@ if sys.platform[:5] == 'linux':
if not _load_time:
_load_time.append(time.time())
try:
- f = open(_proc_pid_stat, 'r')
- l = f.readline().split(' ')
- f.close()
+ with open(_proc_pid_stat, 'r') as f:
+ l = f.readline().split(' ')
return int(l[13])
except Exception:
return int(100*(time.time()-_load_time[0]))