diff options
Diffstat (limited to 'wsgitools/scgi/forkpool.py')
-rw-r--r-- | wsgitools/scgi/forkpool.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/wsgitools/scgi/forkpool.py b/wsgitools/scgi/forkpool.py index b090a54..8ccd579 100644 --- a/wsgitools/scgi/forkpool.py +++ b/wsgitools/scgi/forkpool.py @@ -168,7 +168,8 @@ class SCGIServer: self.state = state def __init__(self, wsgiapp, port, interface="localhost", error=sys.stderr, - minworkers=2, maxworkers=32, maxrequests=1000, config={}): + minworkers=2, maxworkers=32, maxrequests=1000, config={}, + reusesocket=None): """ @param wsgiapp: is the WSGI application to be run. @type port: int @@ -188,6 +189,11 @@ class SCGIServer: @type config: {} @param config: the environ dictionary is updated using these values for each request. + @type reusesocket: None or socket.socket + @param reusesocket: If a socket is passed, do not create a socket. + Instead use given socket as listen socket. The passed socket + must be set up for accepting tcp connections (i.e. AF_INET, + SOCK_STREAM with bind and listen called). """ assert hasattr(error, "write") self.wsgiapp = wsgiapp @@ -198,6 +204,7 @@ class SCGIServer: self.maxrequests = maxrequests self.config = config self.error = error + self.reusesocket = reusesocket self.server = None # becomes a socket # maps filedescriptors to WorkerStates self.workers = {} @@ -218,10 +225,13 @@ class SCGIServer: """ Serve the wsgi application. """ - self.server = socket.socket() - self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.server.bind((self.interface, self.port)) - self.server.listen(5) + if self.reusesocket is None: + self.server = socket.socket() + self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.server.bind((self.interface, self.port)) + self.server.listen(5) + else: + self.server = self.reusesocket self.running = True while self.running: while (len(self.workers) < self.minworkers or # less than min @@ -254,7 +264,8 @@ class SCGIServer: pid, _ = os.waitpid(0, os.WNOHANG) except OSError: pass - self.server.close() + if self.reusesocket is None: + self.server.close() self.server = None self.killworkers() |