Clueless: piping between 2 non-python processes

John Roth newsgroups at jhrothjr.com
Sat Oct 25 14:58:36 EDT 2003


"Michael Lehmeier" <m_lehmeier at gmx.de> wrote in message
news:slrnbplfg1.e7f.m_lehmeier at radom.de...
> Hi, I have a problem.
>
> I have written a big python script with a simple passage like that:
>
> while 1 :
>    if os.system("A | B") == 256 :
>       sys.exit(0)
>
> A is a streaming application, B an encoding application.
> Both are not python.
> Occasionally A terminates and the command is executed again.
> If it is stopped by a SIGINT, os.system returns 256 and the script ends.
>
> The problem is: B can also terminate by itself.
> Whenever this happens, A continues to happily pipe data to a
> non-existant B until eternity or A stops.
>
> So I wanted to start A and B as fork, but all solutions to create a pipe
> between them seem to demand that at least one of the two processes is in
> python itself.
> Or maybe I just understood it wrong.
>
> So the basic problem is:
> - create two processes A and B
> - pipe from A to B
> - terminate A when B ends
>
> Can anybody help?
> Thanks!

You need an intermediary process in Python. Set it up as a
thread so that it receives data from A and sends it to B. Then
you can do whatever you want on exceptional conditions.

John Roth






More information about the Python-list mailing list