suggestion on a complicated inter-process communication

Paul Boddie paul at
Tue Apr 28 18:30:02 CEST 2009

On 28 Apr, 17:44, Way <csw... at> wrote:
> Thanks a lot for the reply. I am not familiar with multi-process in
> Python. I am now using something like:
> A_prog is an os.system to involk Process3
> B_prog is an os.system to involk Process4
> -------------------------------------------------------
> In Main Process:
> Process1 = Popen(["A_prog"], stdin=PIPE, stdout=PIPE)
> Process2 = Popen(["B_prog"], stdin=PIPE, stdout=PIPE)
> cmd = Process2.stdout.readlines()

Careful here: this may want to read until process 2 has closed its
stream, which may only occur on exit, normally.

> Process1.stdin.write(cmd)
> if Process1.poll():
>   Process2.stdin.write("trig from Process1")
> -----------------------------------------
> In Process5 (another python program):
> import sys
> sys.stdout.write("process1 argument")

Careful here, too: this output may not be sent immediately, due to
buffering issues.

> while 1:
>     if sys.stdin.readline().strip() == "trig from Process1":
>             break

And this test may not be satisfied, since the main process may still
be waiting for output from process 5 (via process 2), not reaching the
point where it writes a response.


More information about the Python-list mailing list