mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
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.
This commit is contained in:
parent
a459986cfd
commit
e5f6b8024d
@ -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):
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user