Skip to content

Commit

Permalink
add check_config instance method to workers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benoitc committed Mar 6, 2015
1 parent a459986 commit e5f6b80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def start(self):
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):
Expand Down
9 changes: 8 additions & 1 deletion gunicorn/workers/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,21 @@ def __init__(self, *args, **kwargs):
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
self._lock = None
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()
Expand Down

0 comments on commit e5f6b80

Please sign in to comment.