Skip to content

Commit

Permalink
fix #1004: Process.io_counters() may raise ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Oct 19, 2018
1 parent fbece8e commit 7300bd4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ XXXX-XX-XX
**Bug fixes**

- 715_: do not print exception on import time in case cpu_times() fails.
- 1004_: [Linux] Process.io_counters() may raise ValueError.
- 1277_: [OSX] available and used memory (psutil.virtual_memory()) metrics are
not accurate.
- 1294_: [Windows] psutil.Process().connections() may sometimes fail with
Expand Down
5 changes: 5 additions & 0 deletions IDEAS
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ PLATFORMS
- #82: Cygwin (PR at #998)
- #276: GNU/Hurd
- #693: Windows Nano
- #1251: Windows bash
- DragonFlyBSD
- HP-UX

FEATURES
========

- #1115: users() idle time.

- #1102: Process.is64bit().

- #371: sensors_temperatures() at least for macOS.

- #669: Windows / net_if_addrs(): return broadcast addr.
Expand Down
29 changes: 19 additions & 10 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,18 +1650,27 @@ def io_counters(self):
# https://github.com/giampaolo/psutil/issues/1004
line = line.strip()
if line:
name, value = line.split(b': ')
fields[name] = int(value)
try:
name, value = line.split(b': ')
except ValueError:
# https://github.com/giampaolo/psutil/issues/1004
continue
else:
fields[name] = int(value)
if not fields:
raise RuntimeError("%s file was empty" % fname)
return pio(
fields[b'syscr'], # read syscalls
fields[b'syscw'], # write syscalls
fields[b'read_bytes'], # read bytes
fields[b'write_bytes'], # write bytes
fields[b'rchar'], # read chars
fields[b'wchar'], # write chars
)
try:
return pio(
fields[b'syscr'], # read syscalls
fields[b'syscw'], # write syscalls
fields[b'read_bytes'], # read bytes
fields[b'write_bytes'], # write bytes
fields[b'rchar'], # read chars
fields[b'wchar'], # write chars
)
except KeyError as err:
raise ValueError("%r field was not found in %s; found fields "
"are %r" % (err[0], fname, fields))
else:
def io_counters(self):
raise NotImplementedError("couldn't find /proc/%s/io (kernel "
Expand Down

0 comments on commit 7300bd4

Please sign in to comment.