python 命令行运行 自动休眠_使用Paramiko exec_命令运行命令会导致进程在完成之前休眠...

可能与超时有关。尝试将timeout参数(以秒为单位)添加到调用:exec_command(timeout=20*60)。这是20分钟的例子。

有关详细信息,请参见该方法中的doc string:def exec_command(self, command, bufsize=-1, timeout=None, get_pty=False):

"""

Execute a command on the SSH server. A new `.Channel` is opened and

the requested command is executed. The command's input and output

streams are returned as Python ``file``-like objects representing

stdin, stdout, and stderr.

:param str command: the command to execute

:param int bufsize:

interpreted the same way as by the built-in ``file()`` function in

Python

:param int timeout:

set command's channel timeout. See `Channel.settimeout`.settimeout

:return:

the stdin, stdout, and stderr of the executing command, as a

3-tuple

:raises SSHException: if the server fails to execute the command

"""

我也经历过这个问题接收到stdout.channel.eof_==0

^{pr2}$

stdin,stdout和stderr保持开放。。。在>>> print stdin

>>

>>> print stdout

>>

>>> print stderr

>>

所以没有收到EOF。。。在>>> print stdin.channel.eof_received

0

通常我收到的都是真的标准读(),但为了安全起见,我使用了这个解决方法(有效!):等待超时,强制stdout.channel.close()然后标准读():>>> timeout = 30

>>> import time

>>> endtime = time.time() + timeout

>>> while not stdout.channel.eof_received:

... sleep(1)

... if time.time() > endtime:

... stdout.channel.close()

... break

>>> stdout.read()

'Starting XXX: \n[ OK ]\rProgram started . . .\n'

>>>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值