MultiProcessing Pipe recv blocks even when child process is defunct

我们两清 提交于 2019-12-05 10:15:01

Add child_conn.close() after self.child.start(). It is idiomatic for working with pipes to close unused ends. Also (optionally) provide duplex=False parameter.

The things is, I don't know beforehand whether it is going to close right away.. Normally the child should be able to send and receive. Furthermore I still do not get why this won't work, as is.

  1. child_conn.close() in the parent doesn't mean that child should close its end immediately
  2. parent_conn.recv doesn't return until there is a chance that somebody will child_conn.send(). If child_conn is opened (in child or parent) then there is a chance

If I do use the separate thread, the parent is allowed to close its own connection and everything works fine. Note that you still need to know somehow that the child is done for, to do this

You don't need to know it. You can close as soon as the connection is opened in the child. Calling child_conn.close() in the parent after self.child.start() is fine whatever child does.

Could you explain the duplex option a little bit more also?

duplex=False means that the pipe is unidirectional i.e., you can only call parent_conn.recv() and child_conn.send(). Otherwise it is bidirectional and both connections support send/recv.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!