[paramiko] closing SFTP connections
Robey Pointer
robey at lag.net
Fri Dec 15 11:31:18 PST 2006
On 10 Dec 2006, at 16:53, Michael Gratton wrote:
> Hi guys,
>
> We're using Paramiko for some SFTP transfers and are occasionally
> seeing
> connections not getting closed down correctly. This results in the
> python process seeming to hang. After doing an strace/lsof on such a
> process, it is continually select'ing an SSH connection.
>
> We are closing the connection by calling SFTPClient.close. Looking
> through the code base it seems that this calls Channel.close but not
> Transport.close.
>
> I'm going to try to work around the problem by calling Transport.close
> explicitly after closing the client, but is this something that should
> happen in SFTPClient.close automatically?
An SSH transport can host more than one open channel at a time. For
example, you could have two open SFTP sessions and a shell session
all over the same transport. So having Channel or SFTPClient close
the Transport might prematurely close other sessions.
(I think we used to have a __del__ method on Transport, that would
automatically close itself if it was garbage-collected, but python
interacts badly with __del__ in many cases and I think we decided it
was safer to not have it.)
Since all Channel and SFTPClient objects belong to a single
Transport, if you close the Transport (or SSHClient), it should
automatically close all of its channels. That will let you still
have only one "close()" call.
Hope that helps1
robey
More information about the paramiko
mailing list