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'
This commit is contained in:
Mark Adams 2016-10-28 01:35:24 -05:00 committed by Benoit Chesneau
parent 07f62e26f3
commit 6eb01409da
3 changed files with 11 additions and 11 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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