add on_exit hook

This commit is contained in:
Ben Oswald 2014-05-09 01:06:24 +02:00 committed by benoitc
parent 86bab94c6c
commit 9ade14ae78
3 changed files with 27 additions and 0 deletions

View File

@ -782,6 +782,17 @@ two integers of number of workers after and before change.
If the number of workers is set for the first time, old_value would be
None.
on_exit
~~~~~~~
* ::
def on_exit():
pass
Called just before exiting gunicorn.
The callable needs to accept a single instance variable for the Arbiter.
Server Mechanics
----------------

View File

@ -296,6 +296,7 @@ class Arbiter(object):
self.log.info("Reason: %s", reason)
if self.pidfile is not None:
self.pidfile.unlink()
self.cfg.on_exit(self)
sys.exit(exit_status)
def sleep(self):

View File

@ -1422,6 +1422,21 @@ class NumWorkersChanged(Setting):
None.
"""
class OnExit(Setting):
name = "on_exit"
section = "Server Hooks"
validator = validate_callable(1)
def on_exit(server):
pass
default = staticmethod(on_exit)
desc = """\
Called just before exiting gunicorn.
The callable needs to accept a single instance variable for the Arbiter.
"""
class ProxyProtocol(Setting):
name = "proxy_protocol"