Fast way to send message between 2 child processes? (using a file is too slow?)

Jeff Epler jepler at unpythonic.net
Tue Mar 9 07:56:24 EST 2004


On Mon, Mar 08, 2004 at 08:44:03PM -0800, seberino at spawar.navy.mil wrote:
> Jeff
> 
> Thanks.  What about sockets??  If we
> hardwire child processes to have a fixed ip address
> and port then I can communicate with a socket right?
> 
> Are sockets better or worse than your idea?  Why/Why not?

Once established, you're not likely to notice a difference between an
os.pipe() and a stream socket.

Some differences:

Each end of a socket is typically open for reading *and* writing,
while an os.pipe() is unidirectional.  A socketpair(2) are
"indistinguishable", which I believe means they can both read and
write.  However, socketpair is not in os or socket on my version of
Python, so you face writing additional code if you need this
functionality.

If you use any scheme in which one process creates a listening socket
and another process connects to it, instead of creating both ends and
passing them to the children, the major problem you now have to worry
about is whether *someone else* connects to the first child before the
second child can do so.  The consequences of this problem can range from
a simple DoS to theft of data or execution of hostile code, depending
on what the listening application does.

I'd use an os.pipe() if it's not clearly inadequate, but if you have any
concerns then you should find a way to abstract out the exact nature of
the inter-process communication so that you could establish it in
multiple ways.

Jeff




More information about the Python-list mailing list