read stdout/stderr without blocking

Adriaan Renting renting at astron.nl
Wed Sep 14 04:09:00 EDT 2005


Please note that popen uses pipes, which are block devices, not character devices, so the writes will be done in blocks instead of characters/lines, (you can only read something _after_ the application at the other end of the pipe has done a flush or written 8192 bytes.

When reading from a pty like pexpect does, your read will not block until the stdio block buffer is filled.

Maybe using popen is your problem?  The FAQ of Pexpect explains the problem very clearly.
 
 
>>>Jacek Pop*awski <jpopl at interia.pl> 09/13/05 4:36 pm >>> 
|Grant Edwards wrote: 
|>You're right.  I must have been remembering the behavior of a 
|>network socket.  Apparently, you're supposed to read a single 
|>byte and then call select() again.  That seems pretty lame. 
| 
|I created another thread with single read(), it works, as long as I have 
| only one PIPE (i.e. stderr is redirected into stdout). 
|I wonder is it Python limitation or systems one (I need portable solution)? 
-- 
http://mail.python.org/mailman/listinfo/python-list 




More information about the Python-list mailing list