Polling, Fifos, and Linux

Jeremy Moles jeremy at emperorlinux.com
Fri Jul 8 00:28:11 EDT 2005


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?

I've implemented something very similar in the past in C which works
fine; however, this app immediately takes up 100% of my CPU after the
first read from the fifo, regardless of whatever options I pass to
os.open(). Am I not actually reading the data out of the fifo? Is that
what's causing it to poll infinite thereafter?

Any help would be greatly appreciate, though I'll keep reading and
experimenting in the meantime.

#!/usr/bin/env python

import select
import os

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

poller.register(fifo, select.POLLIN)

while True:
        p = poller.poll()
	# only have one file
        string = os.read(p[0][0], 1)
        if len(string):
                print string




More information about the Python-list mailing list