Nonblocking IO on popen pipe (isn't nonblocking)

Donn Cave donn at u.washington.edu
Thu Apr 11 18:16:21 EDT 2002


Quoth "Noah" <noah at noah.org>:
| Hmm... This sounds suspicious... If FTP won't write its buffered
| output then no application could see it -- that includes the shell!

When you use ftp in a normal session, the shell doesn't see its
output.  You're interacting with the ftp process through the
tty driver.  This phenomenon occurs when output is a pipe, not
when it's a tty.

| Python shouldn't be any different in what it sees.
| If I start FTP from the shell, then how does FTP know 
| when to flush the buffer so that you can see it in a shell?

C stdio I/O, which ftp presumably uses, buffers its output differently
depending on the device.  If it sees that it's writing to a tty, then
it "line buffers" output.  Otherwise, it "block buffers".  That's why
the solution is a device that acts like a pipe but looks like a tty.
(Of course all this is assuming that ftp actually does use stdio.  It
doesn't have to, and I haven't checked.)

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list