From e0c88e73e0686a5fb12ec0e2a7303597a77fec30 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sat, 19 Jan 2013 01:17:49 +0100 Subject: [PATCH] python: Properly abort when over request limit. --- python/ashd-wsgi | 2 +- python/ashd/serve.py | 7 ++++++- python3/ashd-wsgi3 | 2 +- python3/ashd/serve.py | 7 ++++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/python/ashd-wsgi b/python/ashd-wsgi index 807fe2b..01c158f 100755 --- a/python/ashd-wsgi +++ b/python/ashd-wsgi @@ -146,7 +146,7 @@ def mkenv(req): return env if reqlimit != 0: - guard = ashd.serve.calllimiter(reqlimit).call + guard = ashd.serve.abortlimiter(reqlimit).call else: guard = lambda fun: fun() diff --git a/python/ashd/serve.py b/python/ashd/serve.py index 4d5d9ca..14170d7 100644 --- a/python/ashd/serve.py +++ b/python/ashd/serve.py @@ -1,4 +1,4 @@ -import threading, time, logging +import os, threading, time, logging log = logging.getLogger("ashd.serve") seq = 1 @@ -125,3 +125,8 @@ class calllimiter(object): return target() finally: self.__exit__() + +class abortlimiter(calllimiter): + def waited(self, time): + if time > 10: + os.abort() diff --git a/python3/ashd-wsgi3 b/python3/ashd-wsgi3 index db54e6e..ba7038d 100755 --- a/python3/ashd-wsgi3 +++ b/python3/ashd-wsgi3 @@ -146,7 +146,7 @@ def mkenv(req): return env if reqlimit != 0: - guard = ashd.serve.calllimiter(reqlimit).call + guard = ashd.serve.abortlimiter(reqlimit).call else: guard = lambda fun: fun() diff --git a/python3/ashd/serve.py b/python3/ashd/serve.py index 9f9fe7f..fe839a2 100644 --- a/python3/ashd/serve.py +++ b/python3/ashd/serve.py @@ -1,4 +1,4 @@ -import threading, time, logging +import os, threading, time, logging log = logging.getLogger("ashd.serve") seq = 1 @@ -113,3 +113,8 @@ class calllimiter(object): def call(self, target): with self: return target() + +class abortlimiter(calllimiter): + def waited(self, time): + if time > 10: + os.abort() -- 2.11.0