Stop reading process output in Python without hang?

#!/usr/bin/env python “””Start process; wait 2 seconds; kill the process; print all process output.””” import subprocess import tempfile import time def main(): # open temporary file (it automatically deleted when it is closed) # `Popen` requires `f.fileno()` so `SpooledTemporaryFile` adds nothing here f = tempfile.TemporaryFile() # start process, redirect stdout p = subprocess.Popen([“top”], stdout=f) # … Read more