ubuntu16最新版本下iotop无法使用的解决办法

山西快乐十分开奖直播 www.o45a2.cn ubuntu16更新到最新版本,启动iotop出现如下错误:

Traceback (most recent call last):
File “/usr/sbin/iotop”, line 17, in <module>
main()
File “/usr/lib/python2.7/dist-packages/iotop/ui.py”, line 620, in main
main_loop()
File “/usr/lib/python2.7/dist-packages/iotop/ui.py”, line 610, in <lambda>
main_loop = lambda: run_iotop(options)
File “/usr/lib/python2.7/dist-packages/iotop/ui.py”, line 508, in run_iotop
return curses.wrapper(run_iotop_window, options)
File “/usr/lib/python2.7/curses/wrapper.py”, line 43, in wrapper
return func(stdscr, *args, **kwds)
File “/usr/lib/python2.7/dist-packages/iotop/ui.py”, line 501, in run_iotop_window
ui.run()
File “/usr/lib/python2.7/dist-packages/iotop/ui.py”, line 155, in run
self.process_list.duration)
File “/usr/lib/python2.7/dist-packages/iotop/ui.py”, line 434, in refresh_display
lines = self.get_data()
File “/usr/lib/python2.7/dist-packages/iotop/ui.py”, line 415, in get_data
return list(map(format, processes))
File “/usr/lib/python2.7/dist-packages/iotop/ui.py”, line 388, in format
cmdline = p.get_cmdline()
File “/usr/lib/python2.7/dist-packages/iotop/data.py”, line 292, in get_cmdline
proc_status = parse_proc_pid_status(self.pid)
File “/usr/lib/python2.7/dist-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

出错原因:新版本ubuntu16的status信息不一定都是:\t来分割信息的了。iotop还没更新过来,所以分割会出现有些信息分割出来只有一个key,没有value.目前iotop还没更新过来,所以临时解决办法就是跳过这些分割出来只有一列的信息。

 

解决办法:

vi?/usr/lib/python2.7/dist-packages/iotop/data.py

找到196行,将:

[4个空格]try:
[8个空格]for line in open(‘/proc/%d/status’ % pid):
[12个空格]key, value = line.split(‘:’, 1)
[12个空格]result_dict[key] = value.strip()
[8个空格]except IOError:
[12个空格]pass # No such process

更改为:

[4个空格]try:
[8个空格]for line in open(‘/proc/%d/status’ % pid):
[12个空格]try:
[16个空格]key, value = line.split(‘:’, 1)
[12个空格]except:
[16个空格]break
[12个空格]result_dict[key] = value.strip()
[4个空格]except IOError:
[8个空格]pass # No such process

注意python是以空格作为标识的,注意每行前面的空格数量。

打赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注