Put the following into a file hello.py (and easy_install paramiko
if you haven't got it):
hostname,username,password='fill','these','in'
import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname=hostname, username=username, password=password)
i,o,e = c.exec_command('ls /')
print(o.read())
c.close()
Fill in the first line appropriately.
Now type
python hello.py
and you'll see some ls output.
Now instead type
python
and then from within the interpreter type
import hello
and voila! It hangs! It will unhang if you wrap the code in a function foo
and do import hello; hello.foo()
instead.
Why does Paramiko hang when used within module initialization? How is Paramiko even aware that it's being used during module initialization in the first place?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…