[Python-ideas] Supporting already opened sockets in our socket-based server classes
tarek at ziade.org
Wed Jun 6 09:56:17 CEST 2012
What about allowing all our socket servers -- from SocketServer to
WSGIServer, to run with an existing socket.
The use case is to make it easier to write applications that use the
pre-fork model to run several processes against the same socket.
- the main process creates a socket, binds it and listen to it
- the main process forks some subprocesses and pass them the socket fd
- each subprocess recreates a socket object using socket.fromfd() --
so it does not bind it
- each subprocess can accept() connection on the socket
I have a working prototype here :
(don't look at the code I made it quickly just as a proof of concept)
What I am proposing is the following syntax:
if the host passed to the class is of the form:
The class will try to create a socket object against the file descriptor
12, and will not bind() it neither accept() it.
How does that sounds ? If people like the idea I can try to build a
patch for 3.x, and I can certainly release a
backport for 2.x
More information about the Python-ideas