suggestion on a complicated inter-process communication
jgardner at jonathangardner.net
Tue Apr 28 07:57:17 CEST 2009
On Apr 27, 8:59 pm, Way <csw... at gmail.com> wrote:
> Hello friends,
> I have a little messy situation on IPC. Please if you can, give me
> some suggestion on how to implement. Thanks a lot!
> -> denotes create
> MainProcess -> Process1 -> Process3 (from os.system)
> -> Process2 (from os.system) -> Process4 (from
> os.system) ->Process5
> I would like to make the communication between Process1 and Process5.
> Process1 needs Process5's output to provide argument to generate
> Process3, and in turn Process5 needs to wait Process3 finished.
> Thank you very much if you can give a hint.
Abstraction should resolve this. What I mean is that Process2
shouldn't be defined in terms of what it actually does, but what it
appears to do. If you look at each process and think only what its
child processes do and what its parent process expects it to do, then
your job should get a lot simpler. Process1 expects Process2 to
deliver a set of parameters to spawn Process3, and then it will wait
until Process3 terminates.
Looking at it this way, questions come to mind: Why can't Process2 run
Process3 itself? It's unusual to have one process tell another process
what to do when it can simply do it itself.
By the way, I've never seen a time when this kind of design is
necessary. There are other ways around your problem than spawning a
bunch of processes. Each process should really be independent of all
the other processes, doing only a very well-specified task in a well-
specified way. The only time I could think of doing something like
this is when you're getting a webserver setup and Process5 needs to
communicate with Process3 to render the page or something like that.
But even in that case, each process is really independently defined
More information about the Python-list