Wrapper for subprocess.Popen to work across various Python versions, when using the with syntax.

def managed_process(process):
    """Wrapper for subprocess.Popen to work across various Python versions, when using the with syntax."""
    try:
        yield process
    finally:
        for stream in [process.stdout, process.stdin, process.stderr]:
            if stream:
                stream.close()
        process.wait()