passing a socket to a spawned process.

Josiah Carlson jcarlson at uci.edu
Tue Oct 12 12:22:36 EDT 2004


> Is it possible?  In the parent process, I have a socket that binds,
> listens and then accepts new connections (which creates new sockets in
> the process).  I want to be able to pass some of these new sockets to
> a spawned process.  Is it possible, and if so how?
> 
> Any help is much appreciated!!

As someone has already mentioned, if you have the socket before the fork,
you will have the socket after the fork.


I had been working on a general file descriptor passing mechanism for a
few weeks in May, until I gave up.

From what I was able to work out, it is not possible in Windows.
SunOS 5.8 has no issues, and will work almost out of the box (pure
Python) with the right incantation (I have it somewhere if you really
want it).
A few constants are missing from the Linux fcntl.py, so this is not
really possible unless you are willing to patch your kernel and Python.

Googling for the terms: passing file descriptors Python
will get you the list of articles/research that I looked at.

One of those links has source code for the C struct usable with a BSD
for making this happen.  Generally though, you can only pass file
descriptors (sockets) across a UNIX domain socket, or sometimes a pipe
(make it before you fork).


Good luck.
 - Josiah




More information about the Python-list mailing list