A python script is controlling an external application on Linux, passing in input via a pipe to the external applications stdin, and reading output via a pipe from the external applications stdout.
The problem is that writes to pipes are buffered by block, and not by line, and therefore delays occur before the controlling script receives data output by, for example, printf in the external application.
The external application cannot be altered to add explicit fflush(0) calls.
How can the pty module of the python standard library be used with the subprocess module to achieve this?