import threading from subprocess import Popen, PIPE, STDOUT class MyThread(threading.Thread): def run(self): print "before Popen" sp = Popen(["ls", "-al"], stdout=PIPE, stderr=STDOUT) print "before first line" for line in sp.stdout: print line[:-1] print "after last line" t = MyThread() t.start()