如何将数据从一个管道传送到三个不同的进程?在nulfp = open(os.devnull, "w")
piper = Popen([
"come command",
"some params"
], stdout = PIPE, stderr = nulfp.fileno())
pipe_consumer_1 = Popen([
"come command",
"some params"
], stdin = piper.stdout, stderr = nulfp.fileno())
pipe_consumer_2 = Popen([
"come command",
"some params"
], stdin = piper.stdout, stderr = nulfp.fileno())
pipe_consumer_3 = Popen([
"come command",
"some params"
], stdin = piper.stdout, stderr = nulfp.fileno())
pipe_consumer_1.communicate()
pipe_consumer_2.communicate()
pipe_consumer_3.communicate()
piper.communicate()
如果我运行上面的代码,它将产生一个损坏的文件。这意味着管道用户可能没有读取管道器的完整输出。在
这个可以正常工作,但速度慢得多:
^{pr2}$
对于如何使第一个代码片段和第二个代码片段的工作方式相同,有什么建议吗?如果我得到第一个工作方法,这个过程将在1/3的时间内完成。在