我应该担心管道溢出吗?
有两个进程(父进程和子进程)通过管道进行通信。父进程正在等待其子进程退出,然后从管道的读取端读取数据。孩子可能会产生相当多的输出。管道是否有可能因为其中有太多未读数据而失败并丢失一些子进程的输出?
There are two processes (parent and child) communicating through a pipe. The parent is waiting for its child to exit, then reads data from the read end of the pipe. The child may produce quite a lot of output. Is it possible for the pipe to fail because of too much unread data in it and lose some of the child's output?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需担心:在标准 2.6 或 3.0 内核上,管道缓冲区为 64k - 因此,如果缓冲区已满,第一个进程将在写入时阻塞。
另一方面,如果这太小,请在两个工作线程之间使用缓冲区,它具有可配置的内存大小
No need to worry about that: On a standard 2.6 or 3.0 Kernel the pipe buffer is 64k - so the first process will block on write, if the buffer runs full.
If on the other hand this is too little, use
buffer
between the two workers, which has a configurable memory size是的,如果管道填满了子进程块,就会出现死锁。
这也是 python 中遇到的问题,请参阅 [1] 第 17.1.2 节中的 Popen.wait() 警告;他们使用沟通方法来避免这个问题。
[1] http://docs.python.org/library/subprocess.html
Yes, if the pipe fills up the child process blocks and you get a deadlock.
This is a problem encountered also in python, see the Popen.wait() warning at [1], section 17.1.2; they used the communicate method to avoid the issue.
[1] http://docs.python.org/library/subprocess.html