Threads blocking on OpenBSD w/ Python 2.4.2

insyte at gmail.com insyte at gmail.com
Mon Sep 18 15:48:28 EDT 2006


I'm attempting to write a faily simple threaded app that fires off a
thread to select() on a FIFO while the main loop handles data read from
that pipe and a few other tasks.  For some reason, calls to
time.sleep() seem to block until the first time data is dumped into the
pipe.  Clearly, I could work around this quite easily by "priming the
pipe" as it were with a bit of garbage data.  However, I'd rather
understand the problem.

Here's a code snippet:

===========================================
ipList = []

def readPipe(pipeName):
    p = file(pipeName, 'r')
    while True:
        x = select.select([p.fileno()], [], [])
        dataLine = p.readline()
        ipList.append(dataLine)

def main():
    if not os.path.exists('bob'):
        os.mkfifo('bob')
        print "FIFO created."
    print "Starting thread."
    thread.start_new_thread(readPipe, ('bob',))
    print "Thread started."
    while True:
        print time.time()
        time.sleep(1)
===========================================

On Linux and OS X, this behaves as expected.  Running the code
immediately produces output like this:

tarja:~ ben$ ./mycapd
Starting thread.
Thread started.
1158608481.67 []
1158608482.67 []
1158608483.67 []
...

But on OpenBSD I get this:

[ ben at rampart ] $ ./mycapd
Starting thread.
Thread started.
1158608528.5 []

And there it hangs until I dump some data into the fifo.  Then it runs
as expected, dumping out a timestamp every second.

So the question is this:  Am I doing something wrong or is there a
problem on OpenBSD?

-Ben




More information about the Python-list mailing list