Python 3.x Python3从子进程读取标准输出

Python 3.x Python3从子进程读取标准输出,python-3.x,subprocess,Python 3.x,Subprocess,我想启动一个作为子流程的流程。python脚本应该仍然从外部获取控制台输入,以控制子流程的运行情况。为此,我希望定期将子流程的输出打印到控制台,然后读取控制台输入。这是我目前的代码: def start(): child_proccess = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) def check(): print("some tutorial string") lines =

我想启动一个作为子流程的流程。python脚本应该仍然从外部获取控制台输入,以控制子流程的运行情况。为此,我希望定期将子流程的输出打印到控制台,然后读取控制台输入。这是我目前的代码:

def start():
    child_proccess = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)

def check():
    print("some tutorial string")
    
    lines = []

    for line in io.TextIOWrapper(child_proccess.stdout, encoding="utf-8"):
        lines.append(line)

    for line in lines[-10:]:
        print(line)

start()
while True:
    check()
    time.sleep(1)
这里的问题是,通过stdout进行迭代会以某种方式阻塞,这意味着第二个for循环永远不会执行,控制台保持空白