non blocking named pipes
Peter Hansen
peter at engcorp.com
Mon Jun 23 12:28:22 EDT 2003
Yves Serrano wrote:
>
> I have a problem with named pipes....
> I searched in the web, but don't found any working solution....
>
> My Problem is that I have a pipe (/temp/pipe) where sometimes some data
> ist written into, but not very often.
> I try to write a python script that opens the pipe and gets the data if
> its there. I no data is there the script
> should not block, it should immediately exit without data.
>
> How to do that?
>
> I'm using python 2.2 on linux
There may be a better way, but the select.select() function is probably
capable of doing what you need. Just give it timeout parameter of 0
to avoid blocking.
mypipe = open-my-pipe(/temp/pipe)
dr, dw, de = select([mypipe], [], [], 0)
if dr == [mypipe]:
# read from mypipe here...
-Peter
More information about the Python-list
mailing list