xunlei-lixian
xunlei-lixian copied to clipboard
让 list 输出对 pipe 更友好
如果用户的离线文件多时, 一个习惯的动作是
$ lx list | head
但是现有实现会抛出如下异常:
IOError: [Errno 32] Broken pipe
这个修改尝试捕获这个异常.
此外, list
操作默认取回整个离线文件列表, 当文件数较多时速度会受网络延迟的影响, 所以修改为使用 generator 遍历文件列表, 这样就可以做到 lazy fetch 文件列表.
我的离线中有 600 多个文件, 修改前后执行 lx list | head
网络 IO 的对比如下:
ncalls tottime percall cumtime percall filename:lineno(function)
162 3.029 0.019 3.029 0.019 {method 'recv' of '_socket.socket' objects}
7 0.071 0.010 0.071 0.010 {method 'connect' of '_socket.socket' objects}
ncalls tottime percall cumtime percall filename:lineno(function)
42 0.756 0.018 0.756 0.018 {method 'recv' of '_socket.socket' objects}
1 0.014 0.014 0.014 0.014 {method 'connect' of '_socket.socket' objects}
可以用lx list 0-9