Approaches of interprocess communication
Ben Finney
bignose+hates-spam at benfinney.id.au
Fri Feb 16 05:58:49 EST 2007
"exhuma.twn" <exhuma at gmail.com> writes:
> Supposing you have two separate processes running on the same box,
> what approach would you suggest to communicate between those two
> processes.
>
> Let me list the ones I know of:
>
> * Sockets
> Advantage: Supported per se in nearly every programming language
> without even the need to install additional packages
This would be my choice. But first, set up a well-defined *protocol*
(preferably based on text commands) for the two processes to use for
communication; don't have each of them being intricately aware of each
others' implementation.
> Disadvantage: Lot's of code to write, and it's kind of silly to
> communicate via TCP/IP if the processes run on the same machine.
You can cut down on the amount of code by using the standard library
"cmd" module to handle a command interface, hooking the stdin and
stdout of the commandline handler to the socket.
If you're already thinking about cooperating processes, you should
make them network-neutral anyway from the start.
Here's what _The Art of Unix Programming_ has to say on the topic of
text protocols:
<URL:http://www.catb.org/~esr/writings/taoup/html/ch05s01.html>
and IPC tactics for peer processes:
<URL:http://www.catb.org/~esr/writings/taoup/html/ch07s07.html>
--
\ "There are only two ways to live your life. One is as though |
`\ nothing is a miracle. The other is as if everything is." -- |
_o__) Albert Einstein |
Ben Finney
More information about the Python-list
mailing list