class FlushFile(object):
    """Write-only flushing wrapper for file-type objects."""

def __init__(self, f):
    self.f = f

def write(self, x):
    self.f.write(x)
Intercepting stdout of a subprocess while it is running