* Added 'worker_exit' server hook

Fixes #81.
This commit is contained in:
George Kollias 2010-08-13 12:27:02 +03:00 committed by Paul J. Davis
parent 1df1bca7b7
commit 5a4e16cf5b
2 changed files with 18 additions and 0 deletions

View File

@ -446,6 +446,7 @@ class Arbiter(object):
self.log.info("Worker exiting (pid: %s)" % worker_pid) self.log.info("Worker exiting (pid: %s)" % worker_pid)
try: try:
worker.tmp.close() worker.tmp.close()
self.cfg.worker_exit(self, worker)
os.unlink(worker.tmpname) os.unlink(worker.tmpname)
except: except:
pass pass
@ -483,6 +484,7 @@ class Arbiter(object):
try: try:
worker = self.WORKERS.pop(pid) worker = self.WORKERS.pop(pid)
worker.tmp.close() worker.tmp.close()
self.cfg.worker_exit(self, worker)
os.unlink(worker.tmpname) os.unlink(worker.tmpname)
return return
except (KeyError, OSError): except (KeyError, OSError):

View File

@ -632,3 +632,19 @@ class PostRequest(Setting):
The callable needs to accept two instance variables for the Worker and The callable needs to accept two instance variables for the Worker and
the Request. 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.
"""