2016-04-16 16 views
0

あなたは、コードのこの短いビット取る場合:ポート22上でSSHサーバーを実行している任意のシステムに「IP」変数を設定しなぜsshtunnelはSIGINTが私のpythonアプリケーションを閉じるのを防ぐのですか?

import sshtunnel 

# The IP of any system with an SSH server on port 22 
ip = "localhost" 

print "Connecting to ssh..." 
with sshtunnel.open_tunnel(ip, ssh_username="test", 
          ssh_password="test", 
          remote_bind_address=("1.2.3.4", 23)) as server: 

    print "SSH connected" 

print "SSH Closed" 

を、コードを実行する、とCtrl + Cでそれを中断しよう「sshへの接続...」と表示された直後に、トレースバックとフリーズ(終了ではない)が表示されます。 これは何を保持していますか?

+0

を、packet.pyに、このライン上で停止しているようです。 'x = self .__ socket.recv(n)'。 packet.pyはparamikoモジュールのようです。これは誰にでも何か意味がありますか?これは何かsshtunnelライブラリですか、それともparamikoがよりうまく処理すべきでしょうか?または私は何か間違っているのですか? – Tal

+0

これに関連すると思われる:https://github.com/paramiko/paramiko/issues/520。私ができる時を調査します。 – Tal

答えて

1

現時点ではsshtunnelはシグナルを考慮していません。 あなたが実行することで回避することができます:私は上記のコードを実行し、(それが何かを待って凍結です)KeyboardInterrupt後にそれを一時停止するPyCharmを使用する場合は

server = sshtunnel.open_tunnel(ip, ssh_username="test", 
           ssh_password="test", 
           remote_bind_address=("1.2.3.4", 23)) 
try: 
    with server: 
     print "SSH connected" 
except KeyboardInterrupt: 
    print "Pressed Ctrl-C" 
    server._stop_transport() 

print "SSH Closed" 
関連する問題