在我新安装的 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
知道如何解决这个问题吗?
答案1
/proc/(pid)/status
显然,最近的内核版本引入了iotop 不期望的空行:
CapBnd: 0000001fffffffff
CapAmb: 0000000000000000
Seccomp: 0
SpeculationStoreBypass: vulnerable
作为修复的零次近似,编辑(作为 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
哪里if not line.strip(): continue
是新的。请注意,python 没有显式大括号,因此该行的缩进应与其下面的行的缩进相匹配。
(另请参阅https://bugs.launchpad.net/pkg-website/+bug/1773383有关此错误的其他修复。)
答案2
只是为了补充已接受的答案(无法添加评论,因为它们不允许多个空格)
- 搜索Python脚本的文件路径
sudo find ./usr/lib | grep iotop/data.py
- 替换为 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