summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-01-22 08:52:50 +1100
committerGitHub <noreply@github.com>2020-01-22 08:52:50 +1100
commit1d05717115990a1bd5dd547b70cd960354063702 (patch)
tree6f09d3fee9ad16c8f304be51ec9315f352a5a032 /numpy/testing/_private/utils.py
parentb781887a087adfa5df7205b4808dc2052fa52875 (diff)
parentb54108238dbd1ce2673a042b0b270f666ea96e29 (diff)
downloadnumpy-1d05717115990a1bd5dd547b70cd960354063702.tar.gz
Merge pull request #15375 from sethtroisi/misc_cleanups
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]))