Passing file descriptors in Python?

Dan puter_programmer at yahoo.com
Sat Oct 2 15:09:19 EDT 1999


On 2 Oct 1999 17:30:18 GMT, viktor at dtek.chalmers.se (Viktor Fougstedt)
wrote:

>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...


I'm currently needing the module for a project that will run on a
Linux machine and unfortunately Linux does appear to support the
System-V approach.  There is no I_SENDFD or I_RECVFD in the ioctl()
man page.  I have found two example code URLs so far and both use the
socketpair() call which isn't in the Python socket module.  So I'm
assuming my only option is to write a C module to do this?  If I can
get it done it might be a nice compliment to my only other C module
appropriately named hello_world. ;-)

http://www2.awl.com/cseng/books/lad/src/passfd.c
http://x26.deja.com/getdoc.xp?AN=443099042

-Dan









More information about the Python-list mailing list