Passing file descriptors in Python?

Dan puter_programmer at yahoo.com
Sat Oct 2 14:49:57 EDT 1999


On 2 Oct 1999 15:17:53 GMT, tseaver at starbase.neosoft.com (Tres Seaver)
wrote:

>
>In article <37f5aa20.6716735 at news.supernews.com>,
>Dan <puter_programmer at yahoo.com> wrote:
>>
>>
>>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.
>>
>>My goal here is to make a Python based web server that will run on
>>more than one processor simultaniously.  I've already built one that
>>uses threading but unfortunately Python has a global interpreter lock
>>which keeps two threads from running at the same time on a
>>multi-processor machine.  So I need to go with a multi-process scheme
>>in order to take advantage of a multi-processor system but the problem
>>is that I'm having a difficult time figuring out how to pass a file
>>descriptor from one process ro another since the only sample code I
>>can find is written in C.
>
>The bible for this kind of stuff is W. S. Stevens'
>_Unix_Network_Programming_.  Volume 1 of the second edition, section 27.9,
>has exactly the kind of setup you describe.  The mechanism used is quite
>arcane:  essentially, the two processes use a Unix-domain socket to pass
>the descriptor via sendmsg() / recvmsg();  exact details depend on the
>actual kernel used.


Actually, I have Stevens' "Advanced Programming in the Unix
Environment" here (the other two are on their way) and it has a
chapter regarding the process too.  I've read it but unfortunately I'm
just getting started in C.  The most C I've done so far is to write a
hello world extension module for Python. ;-)

There is also a usenet posting that probably has a more specific
example of how to do it under Linux than any of Stevens' books.
http://x26.deja.com/getdoc.xp?AN=443099042

Judging from this I am assuming that it's not possible with pure
Python code since socketpair() is not available under Python. Is there
any paticular reason this function was not included in the Python
socket library?

>From the sounds of it my only option is to turn my hello_world module
into a fdpass module myself.  I don't suppose I'll be re-inventing the
wheel here will I? ;-)

-Dan






More information about the Python-list mailing list