Project

General

Profile

Bug #1263 » murder-lighttpd.py

Python SCGI server that kills lighttpd - jtate, 2007-07-17 17:10

 
#!/usr/bin/env python

import cherrypy
import os
from os.path import *
import sys, urllib

import conary.lib.util


from cherrypy._cpwsgi import wsgiApp

from paste.util.scgiserver import SWAP
from scgi import scgi_server
from types import MethodType
import signal
import socket
import time
import errno

class Root(object):
@cherrypy.expose()
def index(self):
time.sleep(60)
return "Hello World"

cherrypy.config.update({'autoreload.on': False})

class NewSCGIServer(scgi_server.SCGIServer):
def serve_on_socket(self, s):
self.socket = s
self.socket.listen(40)
signal.signal(signal.SIGHUP, self.hup_signal)
while 1:
try:
conn, addr = self.socket.accept()
for x in xrange(3,1024):
try:
os.close(x)
except:
pass
except socket.error, e:
if e[0] != errno.EINTR:
raise # something weird
if self.restart:
self.do_restart()


def serve_application (application, prefix, port):
class rAASCGIAppHandler(SWAP):
def __init__(self, *args, **kwargs):
self.prefix = prefix
self.app_obj = application
SWAP.__init__(self, *args, **kwargs)

server = NewSCGIServer(rAASCGIAppHandler, port=port)

server.serve()

cherrypy.root = Root()

# Start the server
cherrypy.server.start(init_only=True, server_class=None)

serve_application(application=wsgiApp, prefix="/", port=4000)

(2-2/3)