Python 子进程是否产生输出
这个问题与:
如果P 是一个以命令启动的子进程,
import subprocess
P = subprocess.Popen ("command", stdout=subprocess.PIPE)
我们可以通过 P.stdout.readline () 读取 P 产生的输出。但这是一个阻塞读取。如何检查是否有输出可供读取(无阻塞)?
This question is in relation to:
python, subprocess: reading output from subprocess
If P is a subprocess started with a command along the lines of
import subprocess
P = subprocess.Popen ("command", stdout=subprocess.PIPE)
we can read the output P produces by P.stdout.readline (). This is a blocking read though. How can I check if there is output ready for reading (without blocking)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 *nix,那么您可以使用 select 模块来轮询 stdout 文件描述符
If you are using *nix, then you can use the select module to poll the stdout file descriptor