#! /usr/bin/env python3.6 import subprocess, sys, atexit, os COMMAND = ''' import sys while True: txt = sys.stdin.read() if not txt: break sys.stdout.write(txt) ''' def get_process(): cmd = [sys.executable, '-c', COMMAND] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, bufsize=0) return proc if __name__ == '__main__': lst = [get_process() for x in range(8)] atexit.lst = lst for proc in lst: proc.terminate() os.system("ps l|grep %s" % os.getpid()) sys.exit(0)