(embedding) running Python as coprocess
exarkun at intarweb.us
Wed Feb 19 23:01:23 CET 2003
On Wed, Feb 19, 2003 at 09:40:09PM +0000, William Park wrote:
> I've managed to fully embed Python into Bash. But, the result is 1.4Meg
> in size. I'm wondering if there is better and more general way of
> running Python as coprocess in the background.
> That is, with Python running in the background, I want to send one batch
> of commands to Python and read the result back, send another batch and
> read the result, and so on. Python should not terminate between
> batches, because I want to access data from previous calls.
> I've tried something like
> python <fifo.in >fifo.out &
> echo "print 2.0+3.0" > fifo.in
> cat fifo.out
> I get the result, but Python terminates as soon as EOF is reached in the
> <stdin> stream.
> My embedded Python will stay alive between batches. But, this solves
> problem only for Python. Any insight to solving this problem for a any
> external program (ie. Perl, Ruby, etc.) would be greatly appreciated.
Instead of running -just- Python, run a Python program. It can attach
itself to a couple fifos (or a unix socket, or a tcp socket, or ...), read
until EOF, process the string (easy, with exec/eval), write the results out,
then re-open the input file.
There's also a project that keeps a Python interpreter running and lets
you use a mini-interpreter (for the #!) to connect to it, but I forget the
name. It was mentioned on this group a week or two ago, so maybe you can
find it w/ a little searching.
It is practically impossible to teach good programming style to
students that have had prior exposure to BASIC: as potential
programmers they are mentally mutilated beyond hope of
regeneration. -- Dijkstra
up 11 days, 2:28, 4 users, load average: 0.29, 0.18, 0.17
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
More information about the Python-list