CentOS上的iotop命令出错


14

在新安装的CentOS 7.5的终端中使用sudo iotop(最新版本0.6-2.el7)时,出现以下错误消息:

Traceback (most recent call last):
  File "/sbin/iotop", line 17, in <module>
    main()
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 620, in main
    main_loop()
  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
    ui.run()
  File "/usr/lib/python2.7/site-packages/iotop/ui.py", line 155, in run
    self.process_list.duration)
  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

任何想法如何解决此问题?


这个对我有用。使用者名称:Linux 4.4.0-127-通用#153〜14.04.1-Ubuntu iotop版本:iotop 0.6 Phyton版本/usr/bin/python2.7
Marko

Answers:


32

显然,最新的内核版本在/proc/(pid)/statusiotop期望的范围内引入了空行:

CapBnd: 0000001fffffffff
CapAmb: 0000000000000000
Seccomp:    0

SpeculationStoreBypass: vulnerable

作为修订的第零近似值,请编辑(以root用户身份),/usr/lib/python2.7/site-packages/iotop/data.py约为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

if not line.strip(): continue是新的。注意python没有明显的花括号,因此此行的缩进应与其下方的行相匹配。

(有关此错误的其他修复,另请参见https://bugs.launchpad.net/pkg-website/+bug/1773383。)


1
这里是指向该问题的CentOS错误的链接:bugs.centos.org/view.php?id=14864
doshea,2018年

与“ Pympler” Python软件包相同。第147行。if not entry.strip(): continue在解决该问题之前添加。pythonhosted.org/Pympler
Eduardo Lucio

2

只是为了补充已接受的答案(无法添加为注释,因为它们不允许多个空格)

  1. 搜索Python脚本的文件路径
sudo find ./usr/lib | grep iotop/data.py
  1. 替换为sed
sed -i '1n;/key, value = line/i\            if not line.strip(): continue' <script_path>

请小心,并在首次运行时检查一切正常。

对于我的系统,它是:

sudo sed -i '1n;/key, value = line/i\            if not line.strip(): continue' /usr/lib/python2.7/dist-packages/iotop/data.py
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.