Skip to content

Commit 2096e42

Browse files
committed
config: reload-extra without reload
1 parent 903792f commit 2096e42

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

docs/source/settings.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ The default behavior is to attempt inotify with a fallback to file
8282
system polling. Generally, inotify should be preferred if available
8383
because it consumes less system resources.
8484

85+
.. note::
86+
If the application fails to load while this option is used,
87+
the (potentially sensitive!) traceback will be shared in
88+
the response to subsequent HTTP requests.
8589
.. note::
8690
In order to use the inotify reloader, you must have the ``inotify``
8791
package installed.
@@ -114,10 +118,13 @@ Valid engines are:
114118

115119
**Default:** ``[]``
116120

117-
Extends :ref:`reload` option to also watch and reload on additional files
121+
Alternative or extension to :ref:`reload` option to (also) watch
122+
and reload on additional files
118123
(e.g., templates, configurations, specifications, etc.).
119124

120125
.. versionadded:: 19.8
126+
.. versionchanged:: 23.FIXME
127+
Option no longer silently ignored if used without :ref:`reload`.
121128

122129
.. _spew:
123130

gunicorn/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,10 @@ class Reload(Setting):
921921
system polling. Generally, inotify should be preferred if available
922922
because it consumes less system resources.
923923
924+
.. note::
925+
If the application fails to load while this option is used,
926+
the (potentially sensitive!) traceback will be shared in
927+
the response to subsequent HTTP requests.
924928
.. note::
925929
In order to use the inotify reloader, you must have the ``inotify``
926930
package installed.
@@ -956,10 +960,13 @@ class ReloadExtraFiles(Setting):
956960
validator = validate_list_of_existing_files
957961
default = []
958962
desc = """\
959-
Extends :ref:`reload` option to also watch and reload on additional files
963+
Alternative or extension to :ref:`reload` option to (also) watch
964+
and reload on additional files
960965
(e.g., templates, configurations, specifications, etc.).
961966
962967
.. versionadded:: 19.8
968+
.. versionchanged:: 23.FIXME
969+
Option no longer silently ignored if used without :ref:`reload`.
963970
"""
964971

965972

gunicorn/reloader.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@
1414

1515

1616
class Reloader(threading.Thread):
17-
def __init__(self, extra_files=None, interval=1, callback=None):
17+
def __init__(self, extra_files=None, interval=1, callback=None, auto_detect=False):
1818
super().__init__()
1919
self.daemon = True
2020
self._extra_files = set(extra_files or ())
2121
self._interval = interval
2222
self._callback = callback
23+
self._auto_detect = auto_detect
2324

2425
def add_extra_file(self, filename):
2526
self._extra_files.add(filename)
2627

2728
def get_files(self):
29+
if not self._auto_detect:
30+
return self._extra_files
31+
2832
fnames = [
2933
COMPILED_EXT_RE.sub('py', module.__file__)
3034
for module in tuple(sys.modules.values())
@@ -71,12 +75,13 @@ class InotifyReloader(threading.Thread):
7175
| inotify.constants.IN_MOVE_SELF | inotify.constants.IN_MOVED_FROM
7276
| inotify.constants.IN_MOVED_TO)
7377

74-
def __init__(self, extra_files=None, callback=None):
78+
def __init__(self, extra_files=None, callback=None, auto_detect=False):
7579
super().__init__()
7680
self.daemon = True
7781
self._callback = callback
7882
self._dirs = set()
7983
self._watcher = Inotify()
84+
self._auto_detect = auto_detect
8085

8186
for extra_file in extra_files:
8287
self.add_extra_file(extra_file)
@@ -91,6 +96,9 @@ def add_extra_file(self, filename):
9196
self._dirs.add(dirname)
9297

9398
def get_dirs(self):
99+
if not self._auto_detect:
100+
return set()
101+
94102
fnames = [
95103
os.path.dirname(os.path.abspath(COMPILED_EXT_RE.sub('py', module.__file__)))
96104
for module in tuple(sys.modules.values())
@@ -100,6 +108,7 @@ def get_dirs(self):
100108
return set(fnames)
101109

102110
def run(self):
111+
# FIXME: _watchers/_dirs inconsistent - latter gets reset
103112
self._dirs = self.get_dirs()
104113

105114
for dirname in self._dirs:
@@ -117,7 +126,7 @@ def run(self):
117126
else:
118127

119128
class InotifyReloader:
120-
def __init__(self, extra_files=None, callback=None):
129+
def __init__(self, extra_files=None, callback=None, auto_detect=False):
121130
raise ImportError('You must have the inotify module installed to '
122131
'use the inotify reloader')
123132

gunicorn/workers/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def init_process(self):
119119
self.init_signals()
120120

121121
# start the reloader
122-
if self.cfg.reload:
122+
if self.cfg.reload or self.cfg.reload_extra_files:
123123
def changed(fname):
124124
self.log.info("Worker reloading: %s modified", fname)
125125
self.alive = False
@@ -130,7 +130,7 @@ def changed(fname):
130130

131131
reloader_cls = reloader_engines[self.cfg.reload_engine]
132132
self.reloader = reloader_cls(extra_files=self.cfg.reload_extra_files,
133-
callback=changed)
133+
callback=changed, auto_detect=self.cfg.reload)
134134

135135
self.load_wsgi()
136136
if self.reloader:

0 commit comments

Comments
 (0)