Skip to content

Commit

Permalink
[project @ [email protected]]
Browse files Browse the repository at this point in the history
add exit_status_ready for justin cook.
  • Loading branch information
Robey Pointer committed Mar 23, 2008
1 parent c0fc67a commit 7854d60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions paramiko/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ def resize_pty(self, width=80, height=24):
self.transport._send_user_message(m)
self._wait_for_event()

def exit_status_ready(self):
"""
Return true if the remote process has exited and returned an exit
status. You may use this to poll the process status if you don't
want to block in L{recv_exit_status}. Note that the server may not
return an exit status in some cases (like bad servers).
@return: True if L{recv_exit_status} will return immediately
@rtype: bool
@since: 1.7.3
"""
return self.closed or self.status_event.isSet()

def recv_exit_status(self):
"""
Return the exit status from the process on the server. This is
Expand Down
7 changes: 7 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def test_9_exit_status(self):
schan = self.ts.accept(1.0)
chan.exec_command('yes')
schan.send('Hello there.\n')
self.assert_(not chan.exit_status_ready())
# trigger an EOF
schan.shutdown_read()
schan.shutdown_write()
Expand All @@ -292,6 +293,12 @@ def test_9_exit_status(self):
f = chan.makefile()
self.assertEquals('Hello there.\n', f.readline())
self.assertEquals('', f.readline())
count = 0
while not chan.exit_status_ready():
time.sleep(0.1)
count += 1
if count > 50:
raise Exception("timeout")
self.assertEquals(23, chan.recv_exit_status())
chan.close()

Expand Down

0 comments on commit 7854d60

Please sign in to comment.