【发布时间】:2017-07-24 13:28:26
【问题描述】:
我有下一个用c写的程序:
#include <stdio.h>
int main()
{
while(1)
{
printf("hey\n");
}
return 0;
}
还有这个python中的程序
from subprocess import Popen, PIPE
def main():
proc = Popen("procname.o", stdin=PIPE, stdout=PIPE, shell=True)
while True:
print proc.stdout.read()
if __name__ == '__main__':
main()
但这条线会阻塞:
proc.stdout.read()
任何想法为什么?有没有人遇到过这种情况?
【问题讨论】:
-
两个脚本都在执行
while True,没有任何time.sleep()或等效项。也许你在 stackoverflow 中运行?你说的“这条线块”是什么意思?你得到回溯还是什么? -
您正在执行
.o文件?对吗? -
子进程是否正在向 stderr 写入任何内容?
-
Around - 我的意思是进程开始休眠(阻塞状态,等待函数 read() 返回的输出,这会导致一些系统调用) Rawing - 是的,显然我是 :) Luke伍德沃德 - 我现在就去看看
标签: python subprocess stdout