#! /usr/bin/python from subprocess import Popen, PIPE, STDOUT for i in range(10000): print i if 1: p = Popen(['true']) else: p = Popen(['true'], stdin=PIPE, stdout=PIPE, stderr=STDOUT) if 1: p.communicate() else: if p.stdin: p.stdin.close() if p.stdout: p.stdout.read() p.stdout.close() p.wait()