readline() blocks after select() says there's data??

Grant Edwards grante at visi.com
Thu Mar 14 23:29:27 EST 2002


In article <2b57f654.0203141934.391d1bcc at posting.google.com>, wealthychef wrote:

>         selectables = [theProcess.childerr, theProcess.fromchild]
>         (input, output, exc) = select.select([],selectables, selectables)

It looks like you've got the first two parameters to select
reversed.  After the above call, output is going to contain
writable sockets.  If you're wanting to read data, you should
do:

          (output, input, exc) = select.select(selectables,[],selectables)

>         if output:
>              for theOutput in output:
>                 if theOutput == theProcess.childerr:
>                     eoutput = theProcess.childerr.readline(bufsize)
>                     print eoutput
>                 elif theOutput == theProcess.fromchild:
>                     stdoutput = theProcess.fromchild.readline(bufsize)
>                     print stdoutput

I think you're names output/input are confusing since (they're
named from the child's point of view?).  But that's just a
style issue.

BTW, the "if output:" isn't needed.  If the "output" value is
empty, then the for loop executes zero times.

> It blocks forever waiting for theProcess.childerr.readline(bufsize) to
> return.  I expect it to block waiting for select.select();

When select returns a file descriptor, that means that read()
won't block.  If only a partial line is available, then
readline() will still block.  I doubt that this is going to be
an issue, since your output is probably line-oriented.

The code you posted got line-wrapped by your news client, and
I'm too lazy to fix it.  If the above tips don't get things
running, post again (unwrapped code), and I'll give it another
shot.

-- 
Grant Edwards                   grante             Yow!  Am I accompanied by
                                  at               a PARENT or GUARDIAN?
                               visi.com            



More information about the Python-list mailing list