def tee(instream, *outstreams):
    """
    Copy data from instream to all outstreams until EOF, close streams.
    """
    for line in instream:
        for outstream in outstreams:
            outstream.write(line)
    instream.close()
    for outstream in outstreams:
        outstream.close()
