Add post-init hook for workers

Allows a config specifying a function after a worker has been initialized and before the run loop
This commit is contained in:
Philip Cristiano 2013-06-20 17:39:46 -04:00
parent e77d47cb97
commit 0ae7fd760d
2 changed files with 20 additions and 0 deletions

View File

@ -1162,6 +1162,24 @@ class Postfork(Setting):
"""
class Postinit(Setting):
name = "post_init"
section = "Server Hooks"
validator = validate_callable(1)
type = six.callable
def post_init(worker):
pass
default = staticmethod(post_init)
desc = """\
Called just after a worker has initialized the application.
The callable needs to accept one instance variable for the initialized
Worker.
"""
class PreExec(Setting):
name = "pre_exec"
section = "Server Hooks"

View File

@ -99,6 +99,8 @@ class Worker(object):
self.wsgi = self.app.wsgi()
self.cfg.post_init(self)
# Enter main run loop
self.booted = True
self.run()