From 6eb01409da42a81b7020cd78c52613d8ec868e94 Mon Sep 17 00:00:00 2001 From: Mark Adams Date: Fri, 28 Oct 2016 01:35:24 -0500 Subject: [PATCH] Fix validate_reload by returning the validated value (#1378) * Fix validate_reload by returning the validated value When '--reload=RELOADER_TYPE' was implemented, `validate_reload()` was added but in one of the last refactorings, it lost the return statement at the end of the function. As a result, the '--reload' config value was totally broken. This resolves the issue by adding the missing return. * Fix tests by changing --reload to always require an argument - '--reload' always requires an argument now - Added 'auto' as the default value for '--reload' --- docs/source/settings.rst | 6 +++--- gunicorn/config.py | 14 +++++++------- gunicorn/workers/base.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/source/settings.rst b/docs/source/settings.rst index 90bf9b74..eb191896 100644 --- a/docs/source/settings.rst +++ b/docs/source/settings.rst @@ -256,7 +256,7 @@ reload ~~~~~~ * ``--reload RELOADER_TYPE`` -* ``None`` +* ``off`` Restart workers when code changes. @@ -270,8 +270,8 @@ application code or the reload will not work as designed. When using this option, you can optionally specify whether you would like to use file system polling or the kernel's inotify API to watch for changes. Generally, inotify should be preferred if available -because it consumes less system resources. If no preference is given, -inotify will attempted with a fallback to FS polling. +because it consumes less system resources. The default behavior (auto) +is to attempt inotify with a fallback to FS polling. Note: In order to use the inotify reloader, you must have the 'inotify' package installed. diff --git a/gunicorn/config.py b/gunicorn/config.py index 60e93bf7..8369d974 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -492,15 +492,17 @@ def validate_hostport(val): def validate_reloader(val): if val is None: - val = 'default' + val = 'auto' - choices = ['poll', 'inotify', 'default'] + choices = ['auto', 'poll', 'inotify', 'off'] if val not in choices: raise ConfigError( 'Invalid reloader type. Must be one of: %s' % choices ) + return val + def get_default_config_file(): config_path = os.path.join(os.path.abspath(os.getcwd()), @@ -820,9 +822,7 @@ class Reload(Setting): section = 'Debugging' cli = ['--reload'] validator = validate_reloader - nargs = '?' - const = 'default' - default = None + default = 'off' meta = 'RELOADER_TYPE' desc = '''\ @@ -838,8 +838,8 @@ class Reload(Setting): When using this option, you can optionally specify whether you would like to use file system polling or the kernel's inotify API to watch for changes. Generally, inotify should be preferred if available - because it consumes less system resources. If no preference is given, - inotify will attempted with a fallback to FS polling. + because it consumes less system resources. The default behavior (auto) + is to attempt inotify with a fallback to FS polling. Note: In order to use the inotify reloader, you must have the 'inotify' package installed. diff --git a/gunicorn/workers/base.py b/gunicorn/workers/base.py index 885ff6d4..fd259461 100644 --- a/gunicorn/workers/base.py +++ b/gunicorn/workers/base.py @@ -115,7 +115,7 @@ class Worker(object): self.load_wsgi() # start the reloader - if self.cfg.reload: + if self.cfg.reload and self.cfg.reload != 'off': def changed(fname): self.log.info("Worker reloading: %s modified", fname) self.alive = False