When using sudo iotop (latest version 0.6-2.el7) in a terminal in my newly installed CentOS 7.5, I get the following error message:

Traceback (most recent call last):
  File "/sbin/iotop", line 17, in <module>
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 620, in main
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 610, in <lambda>
    main_loop = lambda: run_iotop(options)
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 508, in run_iotop
    return curses.wrapper(run_iotop_window, options)
  File "/usr/lib64/python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 501, in run_iotop_window
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 155, in run
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 434, in refresh_display
    lines = self.get_data()
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 415, in get_data
    return list(map(format, processes))
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 388, in format
    cmdline = p.get_cmdline()
  File "/usr/lib/python2.7/site-packages/iotop/data.py", line 292, in get_cmdline
    proc_status = parse_proc_pid_status(self.pid)
  File "/usr/lib/python2.7/site-packages/iotop/data.py", line 196, in parse_proc_pid_status
    key, value = line.split(':\t', 1)
ValueError: need more than 1 value to unpack

Any idea how to fix this problem?

  • It works for me. uname: Linux 4.4.0-127-generic #153~14.04.1-Ubuntu iotop version: iotop 0.6 Phyton version /usr/bin/python2.7 – Marko Sep 3 '18 at 19:20

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 = {}
        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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.