tdelaney가 말한대로 ssh.close()
을 추가해야합니다. 파이썬 3.3를 사용하여 테스트 :
import paramiko
import getpass
authenticated, tries = False, 1
myhost = 'myserver.mydomain.org'
myusername = 'myuser'
while authenticated == False and tries <= 3:
try:
password = getpass.getpass('Password: ')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(myhost, username=myusername, password=password)
authenticated = True
except paramiko.AuthenticationException:
authenticated = False
tries += 1
if authenticated == False:
print('Too many tries, sorry.')
else:
print('Authenticated')
ssh.close()
이 ssh.close()
없이 스크립트가 I 입력 한 잘못된 암호 다음 오른쪽 비밀번호를 중단됩니다. 그렇지 않으면 (2 잘못된 암호 및 오른쪽 암호를 확인, 응답하지 않습니다) 그렇지 않으면 응답하지 않습니다.
import threading
당신이 경우 마지막 줄 print('Threads:', threading.enumerate())
에서 당신은 활성 스레드를 볼 수 있습니다
Threads: [<_MainThread(MainThread, started 140298690832128)>, <paramiko.Transport at 0x14e3a90 (cipher aes128-ctr, 128 bits) (connected; awaiting auth)>, <paramiko.Transport at 0x147a910 (cipher aes128-ctr, 128 bits) (active; 0 open channel(s))>]
: 나는 그것을 시험 할 때, 그것은 하나의 잘못된 암호 및 올바른 암호를 한 후 인쇄
import paramiko
import getpass
import threading
authenticated, tries = False, 1
myhost = 'myserver.mydomain.org'
myusername = 'myuser'
while authenticated == False and tries <= 3:
try:
password = getpass.getpass('Password: ')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(myhost, username=myusername, password=password)
authenticated = True
except paramiko.AuthenticationException:
authenticated = False
tries += 1
if authenticated == False:
print('Too many tries, sorry.')
else:
print('Authenticated')
#ssh.close()
print('Threads:', threading.enumerate())
나는 이것이 이것이 왜 그렇게하는지 설명하지 않는다는 것을 안다. 그러나 나는 당신의 문제를 해결하고 무슨 일이 일어나고 있는지를 알기를 희망한다.
나를 위해 Python 2.x Linux에서 작동합니다. 관계가 없지만, 스크립트가 끝날 때 ssh 연결을 닫으려고 시도하십시오. 연결이 실패하더라도 -paramiko는 백그라운드 스레드를 실행하고 아마도 그 작업과 관련이 있습니다. – tdelaney