Skip to content

Commit

Permalink
fix #2455 [Linux]: fix IndexError if /proc/pid/stat has no field …
Browse files Browse the repository at this point in the history
…40 (blkio_ticks).
  • Loading branch information
giampaolo committed Oct 5, 2024
1 parent 1054b5e commit 70b6787
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ XXXX-XX-XX

- 2427_: psutil (segfault) on import in the free-threaded (no GIL) version of
Python 3.13. (patch by Sam Gross)
- 2455_, [Linux]: ``IndexError`` may occur when reading /proc/pid/stat and
field 40 (blkio_ticks) is missing.

6.0.0
======
Expand Down
7 changes: 6 additions & 1 deletion psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,12 @@ def _parse_stat_file(self):
ret['children_stime'] = fields[14]
ret['create_time'] = fields[19]
ret['cpu_num'] = fields[36]
ret['blkio_ticks'] = fields[39] # aka 'delayacct_blkio_ticks'
try:
ret['blkio_ticks'] = fields[39] # aka 'delayacct_blkio_ticks'
except IndexError:
# https://github.com/giampaolo/psutil/issues/2455
debug("can't get blkio_ticks, set iowait to 0")
ret['blkio_ticks'] = 0

return ret

Expand Down

0 comments on commit 70b6787

Please sign in to comment.