Paramiko Server: Signalling The Client That Stdout Is Closed
Solution 1:
In check_channel_exec_request
, close the channel on server side once exit status is sent, per protocol specification which states that a channel is active per lifetime of command executed and is closed there after.
This causes channel.eof()
to be True
on client side, indicating command has finished and reading from channel no longer hangs.
def check_channel_exec_request(self,channel,command):
writemessage = channel.makefile("w")
writemessage.write("SOME COMMAND SUBMITTED")
writemessage.channel.send_exit_status(0)
channel.close()
return True
See this embedded server for integration testing based on paramiko that has been around for some years for reference - it implements exec requests among others. Speaking from experience, I would recommend instead using an embedded OpenSSH based server, an example of which can also be found on the same repository. Paramiko code is not particularly bug-free.
Solution 2:
I've experienced a problem that manifested in a similar manner to this. Our issue was that we were closing the whole session as soon as we exited this. Apparently our client (libssh2) didn't like that. So we just keep trying to accept a new channel each time we close one until the transport.is_active()
is False
.
Post a Comment for "Paramiko Server: Signalling The Client That Stdout Is Closed"