Passing file descriptors in Python?

Viktor Fougstedt viktor at dtek.chalmers.se
Sat Oct 2 13:30:18 EDT 1999


puter_programmer at yahoo.com (Dan) writes:



>I suppose I should clarify my request. :-)

>What I want to do is to have a parent process spawn off a child
>process which then waits for new file descriptor (socket) to come from
>the parent.  The parent after it spawns several children will wait
>listen on a socket for new connections which it will pass to one of
>the child processes after the connection has been established.


Depending on the UNIX flavour you use, the passing of open
filedescriptors is done in different ways. On most System-V-based
systems, such as Solaris, sending an open fildescriptor in regular
C-programs requires you to have an open STREAM between the two
processes (a pipe will do fine most of the time). You then ioctl()
this stream with a I_SENDFD in the sender end and a I_RECVFD in the
receiver end, and your filedescriptor will be passed.

I do not know if you can use the fcntl.ioctl() call in Python to do
the same thing, but my guess is it should work (if you are on a
machine whose UNIX dialect supports the I_SENDFD/I_RECVFD ioctls, that
is. Check your local ioctl() manpage). A quick glance at the Python
interpreter's source-code seems to indicate that this _should_ work,
but I'm not certain.

I suppose the best thing would be to actually try it. :-) IPC in UNIX
isn't exactly a breeze to get working properly, and sending
open fildescriptors between otherwise unrelated processes is not the
easiest form of IPC there is, either.

If I get the time tonight, I'll give it a shot and see if I can make
it work.


/Viktor...

-- 
--|     Viktor Fougstedt, system administrator at dtek.chalmers.se     |--
--|                http://www.dtek.chalmers.se/~viktor/                |--
--| ...soon we'll be sliding down the razor blade of life. /Tom Lehrer |--




More information about the Python-list mailing list