Re: Passing socket objects over execution

Adrian Phillips (tandem@freeze.oslo.dnmi.no)
04 Aug 1994 06:36:30 GMT

In article <CtzH5n.2DI@serval.net.wsu.edu> ikao@gandalf.eecs.wsu.edu (I-feng Kao - EECS (CPTS317)) writes:

I am working on interprocess communication(IPC) in python. In the program
I have, I dynamically bind a port, then fork a child so the child process knons
about the hostname and port number. I pass the information with parameters
and the parent process listening for connection for the program that child
process executes. As you may know, when a socket object is listening for a
connection, it stops and waits for ever until connection comes in. However,
this is what I want exectly. Later I worked out two passible solutions which
requires some special techniques:

1. Make the connection before fork(), and pass the socket object over program
execution(for example, os.execlp()). I do not really know if I can do this
or not.

2. Use idle detections with some signal function. This is still not possible
at this time, I have to wait for python 1.0.4 or 1.1, according to Gwido

I am running out of energy at this time. If anyone has a better idea or
solution to passing socket objects, please help me out.

ANY responses, possible solutions, and ideas are WELCOME.

Okay, I'm not sure I've quite worked out what you're trying to do:

parent ->forks-> child->execs->another program
parent must communicate two-ways or one-way with other program ?

- presumably pipes are not good enough (one or two way) ?

- if you want sockets, do a listen then do select on the file
descriptor, and when this completes, do accept, so:

s = socket (AF_INET, SOCK_STREAM, 0)
s.bind ((222.222.222.222, 1040))
s.listen (1)
read, write, exc = select ([s.fileno()],[],[], timeout)
if s.fileno() in read:
news = s.accept ()
s.close()

Note: this is quick hack, use with care :-)

Adrian

--
-------------------------------------------------------------------------
= Adrian Phillips at            | BUT any thoughts in this are purely    =
= The Norwegian Meteorological  | my own and have nothing to do with     =
= Institute   	    	        | this establishment, thankfully.        =
= Net: adrian.phillips@dnmi.no  | Phone: 47 22 96 32 09 Fax: 47 22 96 30 50