Thread blocked by file.read/readline

Donn Cave donn at drizzle.com
Sat May 3 11:09:46 EDT 2003


Quoth "Neil Hodge" <null at null.com>:
...
| etc.  My problem is here:
|
|    def work(self):
|         print 'beginning work'
|         command = './cli.py'
|         print 'beginning os.popen'
|         file = os.popen(command, 'r')
|         print file
|         for f in file.readlines():
|             s = string.strip(f)
|             print 'put in queue: %s' % s
|             self.q.put(f, 1)
|
| Basically, the for loop here does not start processing until it has
| all of the output from the command (i.e., the pipe is closed).  Is
| there any way to read items from the pipe as they are being added (i.e.,
| while the pipe is still open)?  I have some control over the output of the
| CLI, if that helps.  Thanks.

To start with, replace readlines() with readline(), like
   while 1:
       f = file.readline()
       if not f:
           break

If that doesn't do it, then you will have to modify the program on the
other end to get it to flush its output every line.

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list