关于 Python 的 subprocess.Popen() 对象的问题
(请假设为 stdout/stderr 生成的字节数没有填满 OS 管道缓冲区并创建死锁以等待 OS 管道缓冲区接受更多数据)
1) p.stdout.read() 和 p.wait() 的顺序是否重要?
2) stdout/stderr subprocess.PIPE 上的 read() 是否会阻塞,直到进程终止?
3) 即使在进程终止后,stdout/stderr subprocess.PIPE 文件对象和数据是否可用?
import subprocess
process = subprocess.Popen(args="ls", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout = process.stdout.read()
# Does the above read() block until the process has terminated?
stderr = process.stderr.read()
return_code = process.wait()
process = subprocess.Popen(args="ls", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
return_code = process.wait()
# Are stdout and stderr pipes available now, even after the process terminated?
stdout = process.stdout.read()
stderr = process.stderr.read()