感谢这个Answer,我发现必须使用一个从属句柄才能与子进程正确通信:
master, slave = pty.openpty()tokenizer = subprocess.Popen(script, shell=True stdin=subprocess.PIPE, stdout=slave)stdin_handle = process.stdinstdout_handle = os.fdopen(master)
现在,我可以与子流程通信,而无需通过关闭
stdin_handle.write(input)stdout_handle.readline() #gets the processed input



