From a9c916f75238c99bd6161e8898b273fe4cbf10f2 Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Thu, 8 Jul 2010 21:03:36 -0400 Subject: [PATCH] Fix timeouts for async workers. --- gunicorn/workers/async.py | 8 ++++++-- gunicorn/workers/geventlet.py | 9 +-------- gunicorn/workers/ggevent.py | 6 ++---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index 69d04ee37..bdc1df725 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs): self.worker_connections = self.cfg.worker_connections def timeout_ctx(self): - return self.parser.next() + raise NotImplemented() def handle(self, client, addr): try: @@ -29,7 +29,11 @@ def handle(self, client, addr): parser = http.RequestParser(client) try: while True: - req = self.timeout_ctx() + timeout = self.timeout_ctx() + try: + req = parser.next() + finally: + timeout.cancel() if not req: break self.handle_request(req, client, addr) diff --git a/gunicorn/workers/geventlet.py b/gunicorn/workers/geventlet.py index 4c3e3385b..c031aed48 100644 --- a/gunicorn/workers/geventlet.py +++ b/gunicorn/workers/geventlet.py @@ -30,14 +30,7 @@ def init_process(self): super(EventletWorker, self).init_process() def timeout_ctx(self): - timeout = eventlet.Timeout(self.cfg.keepalive) - try: - try: - return super(timeout_ctx, self)() - except eventlet.Timeout, t: - pass - finally: - timeout.cancel() + return eventlet.Timeout(self.cfg.keepalive) def run(self): self.socket.setblocking(1) diff --git a/gunicorn/workers/ggevent.py b/gunicorn/workers/ggevent.py index f1934a5f6..778676088 100644 --- a/gunicorn/workers/ggevent.py +++ b/gunicorn/workers/ggevent.py @@ -23,10 +23,8 @@ def setup(cls): def timeout_ctx(self): timeout = gevent.Timeout(self.cfg.keepalive) - try: - return super(GEventWorker, self).timeout_ctx() - except gevent.Timeout: - return None + timeout.start() + return timeout def run(self): self.socket.setblocking(1)