Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recv_ready reports true when false? #796

Closed
Jim-Wright opened this issue Aug 10, 2016 · 4 comments
Closed

recv_ready reports true when false? #796

Jim-Wright opened this issue Aug 10, 2016 · 4 comments

Comments

@Jim-Wright
Copy link

Jim-Wright commented Aug 10, 2016

This is possibly related to Bug #515, command hangs forever.

I'm running Python 3.5.2, paramiko 2.0.1

I have code that checks to see if I am at a command prompt, I first call recv_ready to see if there is data to be read, and if so, I read it. I have found that if the device I'm talking to stops sending data, recv_ready incorrectly thinks that there is data to be read, which causes a hang.

def checkPrompt():
    if (not ssh_shell.recv_ready):
        print("not ready... ", end='')
        return False
    output = ssh_shell.recv(1000)
    print("read %s characters" % len(output))
    output = output.decode("utf-8")
    # Print the output before stripping characters off
    print(output, end='')
    output = output.strip()
    return output.endswith('#')

The particular command I'm sending to my switch is telling it to tftp a new firmware file to its flash, this takes about 60 seconds, and I'm seeing progress data coming back as expected. Then the unit verifies the firmware, this process takes close to 3 minutes, and no (visible?) output is seen in an SSH session (verified by opening an SSH session with Putty).

During this 3 minute period, my call to the above checkPrompt() should be repeatedly outputting 'not ready..." every time if recv_ready is not true. But I'm not seeing this message appear, so there looks like there is data waiting to be read, but when I call to recv the data, it hangs.

I'm stumped on why this is happening. As far as I know, there is no way to check how much data is waiting on the buffer, or to somehow debug the buffer contents prior to reading the buffer.

@bitprophet
Copy link
Member

Thanks for the report. Might also be related to the trigger condition found in #520 - certainly sounds similar, linking it for fun.

@radssh
Copy link
Contributor

radssh commented Aug 10, 2016

Hmm, are you testing ssh_shell.recv_ready, or ssh_shell.recv_ready() ? The former will always evaluate to True for an instancemethod, and the posted code doesn't show the call ().

@Jim-Wright
Copy link
Author

radssh, you hit the nail on the head, I was missing the () at the end. My code is working as expected now.

@bitprophet
Copy link
Member

Totally missed that one :) thanks @radssh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants