Polling, Fifos, and Linux

Jacob Page apoco at cox.net
Fri Jul 8 07:21:19 CEST 2005


Jeremy Moles wrote:
> This is my first time working with some of the more lower-level python
> "stuff." I was wondering if someone could tell me what I'm doing wrong
> with my simple test here?
> 
> Basically, what I need is an easy way for application in userspace to
> simply echo values "down" to this fifo similar to the way proc files are
> used. Is my understanding of fifo's and their capabilities just totally
> off base?

You shouldn't need to use select.poll(), unless I'm missing something. 
I was able to get the following to work:

-=-=-

import os

fifo = os.open("fifo", os.O_RDONLY | os.O_NONBLOCK)

while True:
     string = os.read(fifo, 1)
     if len(string):
         print string
     # Perhaps add a delay under an else

-=-=-

The Python script, when run, does nothing until you put data into the 
fifo from another process.  Then it immediately spits the data out, 
character by character.

I'm assuming that you've already created the fifo and that it's in the 
current working directory.



More information about the Python-list mailing list