From e5f6b8024d5f28e0abfe3c0cd07ea05c7bc30db4 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Fri, 6 Mar 2015 09:53:44 +0100 Subject: [PATCH] add check_config instance method to workers Add a method to check if config requirements are OK for a specific worker by adding the `check_config` instance method. This method takes 2 arguments: the config instance followed by the logger instance to log. This method is right now used in the thread worker to display a warning in the case it can't handle keep alive connections. This change is related to #979. --- gunicorn/arbiter.py | 3 +++ gunicorn/workers/gthread.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 917ad50e..a53040a2 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -134,6 +134,9 @@ class Arbiter(object): self.log.info("Listening at: %s (%s)", listeners_str, self.pid) self.log.info("Using worker: %s", self.cfg.worker_class_str) + # check worker class requirements + self.worker_class.check_config(self.cfg, self.log) + self.cfg.when_ready(self) def init_signals(self): diff --git a/gunicorn/workers/gthread.py b/gunicorn/workers/gthread.py index 705fc48a..deed4859 100644 --- a/gunicorn/workers/gthread.py +++ b/gunicorn/workers/gthread.py @@ -86,7 +86,6 @@ class ThreadWorker(base.Worker): super(ThreadWorker, self).__init__(*args, **kwargs) self.worker_connections = self.cfg.worker_connections self.max_keepalived = self.cfg.worker_connections - self.cfg.threads - # initialise the pool self.tpool = None self.poller = None @@ -94,6 +93,14 @@ class ThreadWorker(base.Worker): self.futures = deque() self._keep = deque() + @classmethod + def check_config(cls, cfg, log): + max_keepalived = cfg.worker_connections - cfg.threads + + if max_keepalived <= 0 and cfg.keepalive: + log.warning("No keepalived connections can be handled. " + + "Check the number of worker connections and threads.") + def init_process(self): self.tpool = futures.ThreadPoolExecutor(max_workers=self.cfg.threads) self.poller = selectors.DefaultSelector()