files in non-blocking mode?
donn at drizzle.com
Sun Nov 28 19:57:52 CET 2004
Quoth Uwe Mayer <merkosh at hadiko.de>:
| I want two python programs to communicate over stdIO channels. The one
| executes the other via the popen3 function:
| amc = Popen3("./amc/amc.py", True, 0)
| line = stdin.readline()
| print amc.fromchild.readlines()
| The problem is that although amc.tochild gets flushed the data never reaches
| the client until the .tochild fd is closed. Is there any way to put IO
| channels into non-blocking mode in python?
The readlines() function on the last line there will return only when
its file closes. You don't want non-blocking mode, or unbuffered file
objects. As long as both ends are careful to 1) flush the output buffer
after each line of output, and 2) read only one line at a time, with
readline(), the two will get along fine.
Donn Cave, donn at drizzle.com
More information about the Python-list