diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index b918e6e80..03b40158a 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -202,14 +202,10 @@ def run(self): while True: self.maybe_promote_master() - try: - sig = self.SIG_QUEUE.get(timeout=1) - if sig != self.WAKEUP_REQUEST: - if sig != signal.SIGCHLD: - self.log.info("Handling signal: %s", signal.Signals(sig).name) - self.SIG_HANDLERS[sig]() - except queue.Empty: - pass + for sig in self.wait_for_signals(timeout=1): + if sig != signal.SIGCHLD: + self.log.info("Handling signal: %s", signal.Signals(sig).name) + self.SIG_HANDLERS[sig]() self.murder_workers() self.manage_workers() @@ -227,6 +223,16 @@ def run(self): self.pidfile.unlink() sys.exit(-1) + def wait_for_signals(self, timeout=1): + signals = {} # Use dict() instead of set() to keep the insertion order + try: + signals.setdefault(self.SIG_QUEUE.get(timeout)) + while True: + signals.setdefault(self.SIG_QUEUE.get_nowait()) + except queue.Empty: + signals.pop(self.WAKEUP_REQUEST, None) + return signals.keys() + def handle_chld(self): "SIGCHLD handling" self.reap_workers()