diff --git a/docs/source/settings.rst b/docs/source/settings.rst index c271494c..4fc6f64c 100644 --- a/docs/source/settings.rst +++ b/docs/source/settings.rst @@ -300,8 +300,8 @@ Debugging reload ~~~~~~ -* ``--reload RELOADER_TYPE`` -* ``off`` +* ``--reload`` +* ``False`` Restart workers when code changes. @@ -312,14 +312,13 @@ The reloader is incompatible with application preloading. When using a paste configuration be sure that the server block does not import any 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. The default behavior (auto) -is to attempt inotify with a fallback to FS polling. +The default behavior is to attempt inotify with a fallback to file +system polling. Generally, inotify should be preferred if available +because it consumes less system resources. -Note: In order to use the inotify reloader, you must have the 'inotify' -package installed. +.. note:: + In order to use the inotify reloader, you must have the ``inotify`` + package installed. .. _spew: diff --git a/gunicorn/config.py b/gunicorn/config.py index a2f50c51..6dc182c3 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -496,20 +496,6 @@ def validate_hostport(val): raise TypeError("Value must consist of: hostname:port") -def validate_reloader(val): - if val is None: - val = 'auto' - - 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()), 'gunicorn.conf.py') @@ -828,11 +814,9 @@ class Reload(Setting): name = "reload" section = 'Debugging' cli = ['--reload'] - validator = validate_reloader - const = 'auto' - default = 'off' - meta = 'RELOADER_TYPE' - nargs = '?' + validator = validate_bool + action = 'store_true' + default = False desc = '''\ Restart workers when code changes. @@ -844,14 +828,13 @@ class Reload(Setting): paste configuration be sure that the server block does not import any 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. The default behavior (auto) - is to attempt inotify with a fallback to FS polling. + The default behavior is to attempt inotify with a fallback to file + system polling. Generally, inotify should be preferred if available + because it consumes less system resources. - Note: In order to use the inotify reloader, you must have the 'inotify' - package installed. + .. 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 aeec3a2e..d3bdf742 100644 --- a/gunicorn/workers/base.py +++ b/gunicorn/workers/base.py @@ -15,7 +15,7 @@ import traceback from gunicorn import six from gunicorn import util from gunicorn.workers.workertmp import WorkerTmp -from gunicorn.reloader import preferred_reloader, Reloader, InotifyReloader +from gunicorn.reloader import preferred_reloader from gunicorn.http.errors import ( InvalidHeader, InvalidHeaderName, InvalidRequestLine, InvalidRequestMethod, InvalidHTTPVersion, LimitRequestLine, LimitRequestHeaders, @@ -111,7 +111,7 @@ class Worker(object): self.init_signals() # start the reloader - if self.cfg.reload and self.cfg.reload != 'off': + if self.cfg.reload: def changed(fname): self.log.info("Worker reloading: %s modified", fname) self.alive = False @@ -119,14 +119,7 @@ class Worker(object): time.sleep(0.1) sys.exit(0) - if self.cfg.reload == 'poll': - reloader_cls = Reloader - elif self.cfg.reload == 'inotify': - reloader_cls = InotifyReloader - else: - reloader_cls = preferred_reloader - - self.reloader = reloader_cls(callback=changed) + self.reloader = preferred_reloader(callback=changed) self.reloader.start() self.load_wsgi() diff --git a/tests/test_config.py b/tests/test_config.py index ce520faa..2739afd3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -333,3 +333,17 @@ def test_cli_overrides_enviroment_variables_module(monkeypatch): with AltArgs(["prog_name", "-c", cfg_file(), "--workers", "3"]): app = NoConfigApp() assert app.cfg.workers == 3 + + +@pytest.mark.parametrize("options, expected", [ + (["myapp:app"], False), + (["--reload", "myapp:app"], True), + (["--reload", "--", "myapp:app"], True), + (["--reload", "-w 2", "myapp:app"], True), +]) +def test_reload(options, expected): + cmdline = ["prog_name"] + cmdline.extend(options) + with AltArgs(cmdline): + app = NoConfigApp() + assert app.cfg.reload == expected