diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index fd10b1f8..96a9dc58 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -446,6 +446,7 @@ class Arbiter(object): self.log.info("Worker exiting (pid: %s)" % worker_pid) try: worker.tmp.close() + self.cfg.worker_exit(self, worker) os.unlink(worker.tmpname) except: pass @@ -483,6 +484,7 @@ class Arbiter(object): try: worker = self.WORKERS.pop(pid) worker.tmp.close() + self.cfg.worker_exit(self, worker) os.unlink(worker.tmpname) return except (KeyError, OSError): diff --git a/gunicorn/config.py b/gunicorn/config.py index 1cd67830..17884296 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -632,3 +632,19 @@ class PostRequest(Setting): The callable needs to accept two instance variables for the Worker and the Request. """ + +class WorkerExit(Setting): + name = "worker_exit" + section = "Server Hooks" + validator = validate_callable(2) + type = "callable" + def def_worker_exit(server, worker): + pass + def_worker_exit = staticmethod(def_worker_exit) + default = def_worker_exit + desc = """\ + Called just after a worker has been exited. + + The callable needs to accept two instance variables for the Arbiter and + the just-exited Worker. + """