Error with command iotop on CentOS

Apparently, recent kernel versions introduced a blank line in /proc/(pid)/status that iotop does not expect:

CapBnd: 0000001fffffffff
CapAmb: 0000000000000000
Seccomp:    0

SpeculationStoreBypass: vulnerable

As a zeroth approximation of a fix, edit (as root) /usr/lib/python2.7/site-packages/iotop/data.py ca l.195:

def parse_proc_pid_status(pid):
    result_dict = {}
    try:
        for line in open('/proc/%d/status' % pid):
            if not line.strip(): continue
            key, value = line.split(':\t', 1)
            result_dict[key] = value.strip()
    except IOError:
        pass  # No such process

    return result_dict

where the if not line.strip(): continue is new. Beware that python does not have explicit braces, so the indentation of this line should match that of the line below it.

(Also see https://bugs.launchpad.net/pkg-website/+bug/1773383 for other fixes for this bug.)


Just to complement the accepted answer (couldn't add as comment because they don't allow multiple white spaces)

  1. Search for the filepath of the Python script
sudo find ./usr/lib | grep iotop/data.py
  1. Replace with sed
sed -i '1n;/key, value = line/i\            if not line.strip(): continue' <script_path>

Be careful and check everything is ok the first time you run it.

For my systems, it is:

sudo sed -i '1n;/key, value = line/i\            if not line.strip(): continue' /usr/lib/python2.7/dist-packages/iotop/data.py