在CentOS上使用命令iotop时出错
作者:互联网
在我新安装的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
知道如何解决这个问题吗?
解决方法:
显然,最近的内核版本在/ proc /(pid)/ status中引入了一个空行,iotop并不期望:
CapBnd: 0000001fffffffff
CapAmb: 0000000000000000
Seccomp: 0
SpeculationStoreBypass: vulnerable
作为修正的第0个近似值,编辑(作为根)/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不是line.strip():continue是新的.请注意,python没有明确的大括号,因此该行的缩进应该与它下面的行的缩进相匹配.
(另请参阅https://bugs.launchpad.net/pkg-website/+bug/1773383以获取此错误的其他修复.)
标签:python,centos,iotop 来源: https://codeday.me/bug/20190809/1627169.html