summaryrefslogtreecommitdiff
path: root/wsgitools/scgi
diff options
context:
space:
mode:
Diffstat (limited to 'wsgitools/scgi')
-rw-r--r--wsgitools/scgi/forkpool.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/wsgitools/scgi/forkpool.py b/wsgitools/scgi/forkpool.py
index f27cd25..514094f 100644
--- a/wsgitools/scgi/forkpool.py
+++ b/wsgitools/scgi/forkpool.py
@@ -182,7 +182,7 @@ class SCGIServer:
def __init__(self, wsgiapp, port, interface="localhost", error=sys.stderr,
minworkers=2, maxworkers=32, maxrequests=1000, config={},
- reusesocket=None, cpulimit=None):
+ reusesocket=None, cpulimit=None, timelimit=None):
"""
@param wsgiapp: is the WSGI application to be run.
@type port: int
@@ -213,6 +213,10 @@ class SCGIServer:
resource limits are available to this platform. After reaching
the soft limit workers will continue to process the current
request and then cleanly terminate.
+ @type timelimit: int
+ @param timelimit: The maximum number of wall clock seconds processing
+ a request should take. If this is specified, an alarm timer is
+ installed and the default action is to kill the worker.
"""
assert hasattr(error, "write")
self.wsgiapp = wsgiapp
@@ -227,6 +231,7 @@ class SCGIServer:
# master: None or a tuple denoting the limit to be configured.
# worker: boolean denoting whether the limit is reached.
self.cpulimit = cpulimit
+ self.timelimit = timelimit
self.server = None # becomes a socket
# maps filedescriptors to WorkerStates
self.workers = {}
@@ -369,7 +374,11 @@ class SCGIServer:
(con, addr) = self.server.accept()
# we cannot handle socket.errors here.
worksock.sendall('1') # tell server we're working
+ if self.timelimit:
+ signal.alarm(self.timelimit)
self.process(con)
+ if self.timelimit:
+ signal.alarm(0)
worksock.sendall('0') # tell server we've finished
if self.cpulimit:
break