From a2a8bc1ae6fa89110f6b2030d8fb7f3a75f1f5b7 Mon Sep 17 00:00:00 2001 From: Andrew Widdersheim Date: Wed, 20 Feb 2019 15:55:31 -0500 Subject: [PATCH] Move ThreadPoolExecutor() creation into own method Move ThreadPoolExecutor() creation into it's own method so it is easier to override when subclassing. --- gunicorn/workers/gthread.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gunicorn/workers/gthread.py b/gunicorn/workers/gthread.py index 48e93764..a4c4c771 100644 --- a/gunicorn/workers/gthread.py +++ b/gunicorn/workers/gthread.py @@ -85,11 +85,15 @@ class ThreadWorker(base.Worker): "Check the number of worker connections and threads.") def init_process(self): - self.tpool = futures.ThreadPoolExecutor(max_workers=self.cfg.threads) + self.tpool = self.get_thread_pool() self.poller = selectors.DefaultSelector() self._lock = RLock() super(ThreadWorker, self).init_process() + def get_thread_pool(self): + """Override this method to customize how the thread pool is created""" + return futures.ThreadPoolExecutor(max_workers=self.cfg.threads) + def handle_quit(self, sig, frame): self.alive = False # worker_int callback