[paramiko] Possible bug in Channel.fileno()

Richard Cooper lists at richardcooper.net
Thu Oct 25 13:08:33 PDT 2007


Hi all,

I've been playing with using paramiko with select.select() and I  
think I may have found a bug.

My code looks like this (simplified):

"""
ssh_server = paramiko.Transport((host, 22))
ssh_server.connect(username=username, password=password)
session = ssh_server.open_session()
session.exec_command(command)

while 1:
     (r, w, e) = select.select([session], [], [], 10)
     if r:
         got_data = False
         if session.recv_ready():
             data = r[0].recv(4096)
             if data:
                 got_data = True
                 print '**STDOUT**'
                 print data
         if session.recv_stderr_ready():
             data = r[0].recv_stderr(4096)
             if data:
                 got_data = True
                 print '**STDERR**'
                 print data
         if not got_data:
             break
"""

I noticed that the select.select() call returns when there is stdout  
data waiting but it blocks if there is stderr data waiting but  
nothing on stdout. The obvious fix seems to be to add the following  
code to Channel.fileno()

self.in_stderr_buffer.set_event(self._pipe)

to match the existing

self.in_buffer.set_event(self._pipe)

That fixes the problem for me but I have no idea if it's the right  
fix or even if I'm using select.select() correctly . Does it look  
right to you?

I was going to check if this had already been fixed in bazaar but the  
"browse the source using loggerhead" link on http://www.lag.net/ 
paramiko/ isn't working.

Regards,

- Richard




More information about the paramiko mailing list