Threads blocking on OpenBSD w/ Python 2.4.2

I

insyte

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@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
 
I

insyte

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.

I've verified the same behavior with Python 2.5.

-Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,042
Latest member
icassiem

Latest Threads

Top