且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Paramiko 在读取所有输出之前完成过程

更新时间:2023-12-03 20:09:10

我无法用你的命令重现问题,但我可以用像 cat some_big_file.txt 这样的命令重现它.

I couldn't reproduce problem with your command, but I can reproduce it with command like cat some_big_file.txt.

看来您的假设是正确的.在您阅读 channel 中的所有内容之前,退出状态可以准备好.目前还不清楚您是否真的需要使用 select.如果不是,我会重写循环:

So looks like you are right in your hypothesis. Exit status can be ready before you read all the stuff from your channel. It's not clear if you really need to use select. If not I would rewrite loop:

while True:
    buf = channel.recv(1024)
    if not buf:
        break
    print buf

这样的循环会在它有一些数据时继续读取通道.如果你真的想使用 select 你可以把上面的循环放在你的循环之后.它将读取和打印剩余数据.

Such loop will keep reading the channel while it has some data in it. If you really want to use select you can put the above loop just after your loop. It will read and print remaining data.