Last active
August 29, 2015 14:19
-
-
Save ianschenck/315eef1f5de8710743f8 to your computer and use it in GitHub Desktop.
Run twisted wsgi like an old-school, socket sharing fcgi subprocess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Many very old fcgi containers had a trick probably inherited from old | |
# inetd, where a socket is syscall dup2'd onto fd 0 of a subprocess. | |
# The parent creates and binds the socket while the children then just | |
# listen on it. | |
# | |
# Something to note is that supervisord provides this facility with its | |
# [fcgi-program] configuration section. The benefit here is simple inet | |
# or fcgi style graceful restarts. Anyhow, here is how you grab a | |
# socket that is fd 0 and start your twisted wsgi container on it. The | |
# wsgi application here is `application`. | |
from twisted.internet import fdesc | |
from twisted.internet import reactor | |
from twisted.web.server import Site | |
from twisted.web.wsgi import WSGIResource | |
resource = WSGIResource(reactor, reactor.getThreadPool(), application) | |
site = Site(resource) | |
fdesc.setNonBlocking(0) | |
reactor.adoptStreamPort(0, socket.AF_INET, site) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment