From 5c4b77cd02c3212b54e7f51a4c7e7b6aa121037c Mon Sep 17 00:00:00 2001 From: Qiangning Hong Date: Thu, 21 Nov 2013 14:39:09 +0800 Subject: [PATCH] Run worker's setup early than set num_workers `cfg.worker_class` is a property, which calls the classmethod `setup` of the worker class when accessed. Gevent worker relies on this mechanism to call `gevent.monkey.patch_all()`. However, `num_workers` is a hooked property, when it is set, gunicorn will call hook defined by user. If the hooked code relies on gevent's monkey patch, it will fail because the monkey patch has not been applied yet. This commit makes sure that `worker_class` property getter invokes before `num_workers` setter to resolve this problem. --- gunicorn/arbiter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index aaec3187..cd3466c9 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -93,12 +93,12 @@ class Arbiter(object): if 'GUNICORN_FD' in os.environ: self.log.reopen_files() + self.worker_class = self.cfg.worker_class self.address = self.cfg.address self.num_workers = self.cfg.workers self.debug = self.cfg.debug self.timeout = self.cfg.timeout self.proc_name = self.cfg.proc_name - self.worker_class = self.cfg.worker_class if self.cfg.debug: self.log.debug("Current configuration:")