From 85b12af1ca5c885b10f04cd5062df5ffef751e90 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Wed, 17 Feb 2010 10:59:33 +0100 Subject: [PATCH] make sur app can override options if needed. While I'm here clean a little the code --- gunicorn/config.py | 2 +- gunicorn/main.py | 34 +++++++++------------------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/gunicorn/config.py b/gunicorn/config.py index 4640e5c8..3188bc26 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -92,7 +92,7 @@ class Config(object): workers = int(self.conf["workers"]) if not workers: raise RuntimeError("number of workers < 1") - if self.conf['debug'] == True: + if self.conf['debug'] == True: workers = 1 return workers diff --git a/gunicorn/main.py b/gunicorn/main.py index 940bccfa..518e3d4f 100644 --- a/gunicorn/main.py +++ b/gunicorn/main.py @@ -122,24 +122,14 @@ def main(usage, get_app): version="%prog " + __version__) opts, args = parser.parse_args() - conf = Config(opts.__dict__) app = get_app(parser, opts, args) - - workers = conf['workers'] - addr = conf['address'] - - kwargs = dict( - config=conf, - debug=conf['debug'], - pidfile=conf['pidfile'] - ) - - arbiter = Arbiter(addr, workers, app, **kwargs) + conf = Config(opts.__dict__) + arbiter = Arbiter(conf.address, conf.workers, app, config=conf, + debug=conf['debug'], pidfile=conf['pidfile']) if conf['daemon']: daemonize(conf['umask']) else: os.setpgrp() - set_owner_process(conf['user'], conf['group']) configure_logging(conf) arbiter.run() @@ -160,7 +150,7 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None, else: bind = host options['bind'] = bind - + if global_conf: for key, value in list(global_conf.items()): if value and value is not None: @@ -168,7 +158,7 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None, conf = Config(options) arbiter = Arbiter(conf.address, conf.workers, app, debug=conf["debug"], - pidfile=pidfile=conf["pidfile"], config=conf) + pidfile=conf["pidfile"], config=conf) if conf["daemon"] : daemonize(conf["umask"]) else: @@ -259,10 +249,8 @@ def run_paster(): ctx = loadwsgi.loadcontext(loadwsgi.SERVER, config_url, relative_to=relative_to) - if opts.workers: - workers = opts.workers - else: - workers = int(ctx.local_conf.get('workers', 1)) + if not opts.workers: + opts.workers = ctx.local_conf.get('workers', 1) if not opts.umask: opts.umask = int(ctx.local_conf.get('umask', UMASK)) @@ -282,13 +270,9 @@ def run_paster(): else: bind = host opts.bind = bind - - debug = ctx.global_conf.get('debug') == "true" - if debug: - # we force to one worker in debug mode. - workers = 1 - opts.workers=workers + if not opts.debug: + opts.debug = (ctx.global_conf.get('debug') == "true") app = loadapp(config_url, relative_to=relative_to) return app