Non blocking IO

Graeme Winter g.winter at dl.ac.uk
Mon Feb 17 07:07:00 EST 2003


Howdy all,

I have opened a pipe to a program using popen2.Popen3, and I am readling 
the output using readline(). However, this program has a small tendency 
to get stuck, and I need a method for timing this out, so that if I 
don't receive a line for say 10 seconds I raise a RuntimeError. However, 
I have attempted to implement such using select.select() and it doesn't 
work, because the readline() blocks - any solutions out there?

I have (just) tried writing a little doufer in C to wrap fcntl (I know 
there is a fcntl module) and I get:

Traceback (most recent call last):
   File "test_blocking.py", line 43, in ?
     blocking_test(5)
   File "test_blocking.py", line 33, in blocking_test
     line = stdout.readline()
IOError: [Errno 11] Resource temporarily unavailable

Which I guess means that readline() doesn't like non blocking fd's....

What do people do here?

Cheers,

Graeme





More information about the Python-list mailing list