시간 제한과 관련 될 수 있습니다. 통화에 timeout
매개 변수 (초 단위)를 추가하십시오 (exec_command(timeout=20*60)
). 이것은 20 분 예입니다. 대한 추가 정보를 원하시면 그 방법의 문서화 문자열을 참조하십시오 https://github.com/paramiko/paramiko/issues/109
나는이 문제가 발생 https://github.com/paramiko/paramiko/issues/109#issuecomment-111621658
내 제안을 시도해보십시오
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_received == 0으로 인한 것입니다.
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("1.1.1.1", username="root", password="pass")
stdin, stdout, stderr = client.exec_command("service XXX start")
stdout, stdout 및 stderr은 보통 내가 진정한받을 수있는 단지 stdout.read(),하지만 난 이것을 사용 안전을 위해
>>> print stdin.channel.eof_received
0
>>> print stdin
<paramiko.ChannelFile from <paramiko.Channel 3 (open) window=2097152 in-buffer=50 -> <paramiko.Transport at 0x17eff90L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>
>>> print stdout
<paramiko.ChannelFile from <paramiko.Channel 3 (open) window=2097152 in-buffer=50 -> <paramiko.Transport at 0x17eff90L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>
>>> print stderr
<paramiko.ChannelFile from <paramiko.Channel 3 (open) window=2097152 in-buffer=50 -> <paramiko.Transport at 0x17eff90L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>
그래서 EOF가 수신되지
...
... 개방 머물고있는 (작품!) 해결 방법 : stdout.channel.close를 (강제로, 타임 아웃 기다립니다) 다음 stdout.read은() : http://stackoverflow.com/a/ :
>>> 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'
>>>
내 업데이트 된 대답을 참조하십시오 36736691/4988742 그게 해결되는지 알려주세요. 이미 해결했다면 솔루션을 친절하게 공유하십시오. –