* 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'
--reload = Runs the reloader with inotify if available and falls back on
FS polling.
--reload=inotify = Forces the reloader to run with inotify
--reload=poll = Forces the reloader to use FS polling
Currently, '--reload' uses FS polling to find out when files have
changed. For some time, the Linux kernel has had a feature called
inotify that allows applications to monitor for FS events without
polling.
This commit adds a new 'use-inotify' configuration option that will
cause gunicorn to use the new 'InotifyReloader' instead of the default
'Reloader' when 'reload' is enabled.
Using inotify can result in lower CPU consumption by gunicorn especially
when working with virtualized filesystems or environments with a large
number of watched files / directories.
Killing ourself when using the `--reload` option trigger an infinite loop under some monitoring services like the one in pycharm and don't reload the file.
Instead set self.alive as False which will trigger later the worker exit. Note that if we want to force the exit we could also use sys.exit(0) .
fix#1129
in python 3.5 the select is blocking when waiting for it which prevent quick
exit on SIGTERM.
The problem is described:
https://www.python.org/dev/peps/pep-0475/#backward-compatibility
This change fix it by listening for signal event on the worker pipe. Once an
event is triggered it will forcefully wake up the select and return.
fix#1256
The run loop has to change slightly to support graceful shutdown.
There is no way to interrupt a call to `futures.wait` so instead
the pattern, used by the async workers, is to sleep for only one
second at the most. The poll is extended to a one second timeout
to match.
Since threads are preemptively scheduled, it's possible that the
listener is closed when the request is actually handled. For this
reason it is necessary to slightly refactor the TConn class to store
the listening socket name. The name is checked once at the start of
the worker run loop.
Ref #922
Since the changes from #1126, errors are not raised into the main
loop during a non-graceful shutdown. Therefore, these exception
clauses shouldn't be needed anymore.
Just like in the gevent worker, a blocking call should only be executed
from within a coroutine. The AssertionError around the main loop of the
eventlet worker can be removed, since it was there to catch
the exception raised by the sleep.
When the worker was exiting, eventlet is closing the listening socket in th
worker. Since the socket instances are shared, this was also removing the unix
socket on close. This change make sure that the socket can only be closed by
its parent (where the socket have been bound).
While I'm here, also make sure we don't use any blocking function in eventlet
while switching).
fix#965
Add a method to check if config requirements are OK for a specific worker by
adding the `check_config` instance method. This method takes 2 arguments: the
config instance followed by the logger instance to log.
This method is right now used in the thread worker to display a warning in
the case it can't handle keep alive connections. This change is related to #979.