diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-01-22 08:52:50 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-22 08:52:50 +1100 |
commit | 1d05717115990a1bd5dd547b70cd960354063702 (patch) | |
tree | 6f09d3fee9ad16c8f304be51ec9315f352a5a032 /numpy/testing/_private/utils.py | |
parent | b781887a087adfa5df7205b4808dc2052fa52875 (diff) | |
parent | b54108238dbd1ce2673a042b0b270f666ea96e29 (diff) | |
download | numpy-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.py | 10 |
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])) |