(embedding) running Python as coprocess
Carlos Ribeiro
cribeiro at mail.inet.com.br
Wed Feb 19 21:39:48 EST 2003
On Wednesday 19 February 2003 22:38, William Park wrote:
> Finally found 'exec' solution, thanks to Jp. I've come up with the
> following:
>
> import sys
> fifo_in = sys.argv[1]
> fifo_out = sys.argv[2]
> while 1:
> fin = open(fifo_in, "r")
> fout = open(fifo_out, "w")
> sys.stdout = fout
> exec fin
> sys.stdout.flush()
> fout.close()
> fin.close()
>
> If this is called 'coprocess.py', then you can do
>
> mkfifo in out
> python coprocess.py in out &
>
> echo "print 1.0+2.0" > in
> cat out
> echo "import math" > in
> echo "print math.pi" > in
> cat out
Another good candidate for our dear Python Cookbook?
--
Carlos Ribeiro
cribeiro at mail.inet.com.br
More information about the Python-list
mailing list