Paramiko SSH Tunnel Shutdown Issue

前端 未结 4 878
萌比男神i
萌比男神i 2021-02-10 23:36

I\'m working on a python script to query a few remote databases over an established ssh tunnel every so often. I\'m fairly familiar with the paramiko library, so that was my cho

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-11 00:09

    It appears the SocketServer's shutdown method isn't properly shutting down/closing the socket. With the below changes in my code, I retain access to the SocketServer object and access the socket directly to close it. Note that socket.close() works in my case, but others might be interested in socket.shutdown() followed by a socket.close() if other resources are accessing that socket.

    [Ref: socket.shutdown vs socket.close

    def ThreadTunnel():
        self.t = ForwardServer(('127.0.0.1', 3333), SubHandler)
        self.t.serve_forever()
    Thread(target=ThreadTunnel).start()
    
    def stopTunnel(self):
        self.t.shutdown()
        self.trans.close()
        self.c.close()
        self.t.socket.close()
    

提交回复
热议问题