Problems with select

Robin Munn rmunn at pobox.com
Tue Feb 26 18:01:30 CET 2002


On Tue, 26 Feb 2002 04:17:30 +0100, Alain Tesio <alain at onesite.org> wrote:
>Hi, I can't manage to make select work, in both 1.52 and 2.1.2
>
>I just want to read stderr and stdout when executing a command
>with popen3, and I must use select, read() blocks when there is
>more than a fixed amount of data (4 KB I think)
>
>The problems is that select still gives something after the end
>of the file, or sometimes never returns anything at all.
>
>I create the pipes with :
>
>(pipe_out,pipe_in,pipe_err)=popen2.popen3(command)
>
>and use select like this:
>
>pollstatus=select.select([],[pipe_out],[pipe_err],1)
>
>
>(the doc says : select(iwtd, owtd, ewtd[, timeout])
>I didn't put pipe_in as it's closed)

I don't think you've understood the documentation completely. The three
lists you pass to select() are lists of objects for input, output, and
"exceptional conditions" (which are things like out-of-band data in
TCP/IP sockets). Here, "input" and "output" means from the point of view
of your program: if you want to be informed when a pipe has data waiting
for you to read, you put it in the input list.

So what I think you should be doing is:

pollstatus=select.select([pipe_out, pipe_err], [], [], 1)

Hope this helps.

-- 
Robin Munn
rmunn at pobox.com



More information about the Python-list mailing list