From 3be8476021f89a4f11f426760e5f16360da1fb59 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Sun, 13 Mar 2016 14:30:48 -0700 Subject: [PATCH] [eventlet] handle QUIT in a new coroutine Just like in the gevent worker, a blocking call should only be executed from within a coroutine. The AssertionError around the main loop of the eventlet worker can be removed, since it was there to catch the exception raised by the sleep. --- gunicorn/workers/geventlet.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gunicorn/workers/geventlet.py b/gunicorn/workers/geventlet.py index dcb2f3d64d..859c1eaf78 100644 --- a/gunicorn/workers/geventlet.py +++ b/gunicorn/workers/geventlet.py @@ -94,6 +94,9 @@ def init_process(self): self.patch() super(EventletWorker, self).init_process() + def handle_quit(self, sig, frame): + eventlet.spawn(super(EventletWorker, self).handle_quit, sig, frame) + def timeout_ctx(self): return eventlet.Timeout(self.cfg.keepalive or None, False) @@ -118,11 +121,7 @@ def run(self): while self.alive: self.notify() - try: - eventlet.sleep(1.0) - except AssertionError: - self.alive = False - break + eventlet.sleep(1.0) self.notify() try: