Getting STDOUT and STDERR from subprocess.Popen synchronously
===

I'm looking to write some simple utilities that call native executables/scripts. I'm already fairly familiar with using `subprocess.Popen` to open processes, but I don't understand how to effectively get access to the subprocess' STDOUT and STDERR synchronously in Python. I understand that I can pass it a `file`-like object and it'll work fine, but how exactly do I do that? I don't want to write it to an actual filesystem file, so how do I do this? Do I need the `mmap.mmap()` memory file API?

I'd like to do something like this:

    class CoolReader():
    
        def __init__(self, target):
            self.target = target 
 
        def write(self, output):
            self.target.append({timestamp: time.time(), value: output})

    stdoutLines = []
    stderrLines = []

    stdoutReader = CoolReader(stdoutLines)
    stderrReader = CoolReader(stderrLines)

    subprocess.Popen("ls", stdout=stdoutReader, stderr=stderrReader)

Is there a better way of doing this? I'd basically like to have a listener be fired every time a line is written to STDOUT or STDERR to synchronously write file lines to an array or something. How can I/should I do this?