sending data to another process's input stream?
Steven D. Majewski
sdm7g at Virginia.EDU
Thu May 20 18:16:25 EDT 1999
On Thu, 20 May 1999, Joe Strout wrote:
> In article <14148.28634.948802.403019 at amarok.cnri.reston.va.us>, Andrew
> M. Kuchling <akuchlin at cnri.reston.va.us> wrote:
>
> > The most frequent solution would be to use sockets, whether
> > Unix or TCP/IP.
>
> Ugh. I was afraid you'd say that. But what's the difference between
> Unix and TCP/IP sockets? I poked around the Python library reference,
> and found only "sockets" (no distinction).
>
Unix sockets are just "named pipes" . Open with AF_UNIX instead of
AF_INET in the socket call. You bind to a name ( which gets entered
into the directory namespace just like a file ) instead of a well
known port number. ( This isn't in the Python reference because it's
specific to the hosts socket implementation. There's not AF_UNIX mode
on MacPython for example (not that it couldn't be emulated).)
You can also use AF_INET sockets and the 'loopback' address when you're
client & server are one the same host, but Unix sockets should be
more effecient.
> > So, you could write a Python program that would be a long-lived
> > server and accepted connections over a Unix or TCP/IP socket; CGIs
> > would then talk to the server. (This is how Zope works, for example.)
> > Your server could then just act as a front-end for a single
> > long-running instance of the C++ program, sending output to the
> > program's standard input.
>
> Hmm... but that doesn't help, does it? Before, my question was how to
> get the short-lived CGIs talking to my long-lived C++ program. With
> your suggestion, the question is how to get the long-lived Python
> server to talk to the long-lived C++ program. It's the same question,
> is it not?
I think by "Your server could..." he meant the short-lived CGI which
gets run from your HTTP server. ( Which, if it is run from inetd
is also 'short-lived', which is why it's not usually run from inetd.)
Zope works very much like what you want, except that Zope serves
persistent Python objects, and you want to serve C++ objects.
( Unless you want to wrap you C++ objects as Python objects and
do it all in Python. )
> Put another way, how would I implement this part:
>
> > Your server could then just act as a front-end for a single
> > long-running instance of the C++ program
>
> ? Are sockets the way to go, or is there anything easier?
sockets are probably the easiest.
---| Steven D. Majewski (804-982-0831) <sdm7g at Virginia.EDU> |---
---| Department of Molecular Physiology and Biological Physics |---
---| University of Virginia Health Sciences Center |---
---| P.O. Box 10011 Charlottesville, VA 22906-0011 |---
Caldera Open Linux: "Powerful and easy to use!" -- Microsoft(*)
(*) <http://www.pathfinder.com/fortune/1999/03/01/mic.html>
More information about the Python-list
mailing list