Is there a portable way to tell if data is available on a pipe?

Scott David Daniels Scott.Daniels at Acm.Org
Mon Jan 21 12:31:33 EST 2008


John Nagle wrote:
>    I need some way to find out if a pipe has data available for
> a read without blocking if it does not.
...
>  I'd like to avoid having a thread to manage each pipe, but if I
> have to, so be it.

Well, without granting your wish, put a Queue.Queue "in front" of
each pipe.  The per-pipe thread reads a chunk, waiting if it has to,
and then writes to the queue.  To read from a pipe w/o waiting from
one of these assemblies, you can use the get_nowait method on the
associated queue.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list