files in non-blocking mode?

Donn Cave donn at
Sun Nov 28 19:57:52 CET 2004

Quoth Uwe Mayer <merkosh at>:
| Hi,
| I want two python programs to communicate over stdIO channels. The one
| executes the other via the popen3 function:
| amc = Popen3("./amc/", True, 0)
| line = stdin.readline()
| amc.tochild.write(line)
| amc.tochild.flush()
| 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

More information about the Python-list mailing list