Problems with select

Donn Cave donn at u.washington.edu
Wed Feb 27 02:20:05 CET 2002


Quoth Alain Tesio <alain at onesite.org>:

| 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(),
with os.read().

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list