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.
child_conn.close()
in the parent doesn't mean that child should close its end immediatelyparent_conn.recv
doesn't return as long as there is a chance that somebody willchild_conn.send()
. Ifchild_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.