Problems with select

Donn Cave donn at
Tue Feb 26 20:20:05 EST 2002

Quoth Alain Tesio <alain at>:

| Hi, thanks for the explanation, but select still returns files where
| there is nothing to read, after the end of the stream.

Yes, that will happen.  select doesn't care whether a read will return
"something" or "nothing", as long as it will return.  Once you have
gotten an empty string back (at "end of file"), you should remove the
file from the list of files.

And there's another problem that you won't see in your example, but may
be a problem in real life.  To see it , change your command to
"echo one; echo two; sleep 2; echo three"

You would expect "one" and "two" to show up together, but "two" will
actually show up with "three".  Because your readline() reads all the
pipe system buffer into a local process buffer, where select doesn't
see it.  You may be able to solve this by unbuffering the file objects,
or you might find that it simplifies matters to forget about the file
objects and use the file descriptors you already get with fileno(),

	Donn Cave, donn at

More information about the Python-list mailing list