summaryrefslogtreecommitdiff
path: root/wsgitools/scgi/asynchronous.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2011-08-19 21:01:52 +0200
committerHelmut Grohne <helmut@subdivi.de>2011-08-19 21:01:52 +0200
commit6bb3c64529ab99866de5db70f06d00e2c50b30a5 (patch)
treeea60e6e325ed1c443b9d29f73d3b8e4599a636ea /wsgitools/scgi/asynchronous.py
parent8ab2290c24d90d5ff862b68455d0c7b88d5dedc1 (diff)
downloadwsgitools-6bb3c64529ab99866de5db70f06d00e2c50b30a5.tar.gz
scgi: support reusing a listen socket
This is useful when used in combination with e.g. systemd.
Diffstat (limited to 'wsgitools/scgi/asynchronous.py')
-rw-r--r--wsgitools/scgi/asynchronous.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/wsgitools/scgi/asynchronous.py b/wsgitools/scgi/asynchronous.py
index 75f1ff0..e1dbcc6 100644
--- a/wsgitools/scgi/asynchronous.py
+++ b/wsgitools/scgi/asynchronous.py
@@ -191,7 +191,7 @@ class SCGIServer(asyncore.dispatcher):
multiple threads."""
def __init__(self, wsgiapp, port, interface="localhost", error=sys.stderr,
maxrequestsize=None, maxpostsize=None, blocksize=None,
- config={}):
+ config={}, reusesocket=None):
"""
@param wsgiapp: is the wsgi application to be run.
@type port: int
@@ -215,8 +215,16 @@ class SCGIServer(asyncore.dispatcher):
@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).
"""
- asyncore.dispatcher.__init__(self)
+ if reusesocket is None:
+ asyncore.dispatcher.__init__(self)
+ else:
+ asyncore.dispatcher.__init__(self, reusesocket)
self.wsgiapp = wsgiapp
self.error = error
@@ -229,10 +237,11 @@ class SCGIServer(asyncore.dispatcher):
self.conf["blocksize"] = blocksize
self.conf["config"] = config
- self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
- self.set_reuse_addr()
- self.bind((interface, port))
- self.listen(5)
+ if reusesocket is None:
+ self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.set_reuse_addr()
+ self.bind((interface, port))
+ self.listen(5)
def handle_accept(self):
"""asyncore interface"""