diff --git a/gunicorn/config.py b/gunicorn/config.py index 1ce7e46b..73664038 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -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" diff --git a/gunicorn/workers/base.py b/gunicorn/workers/base.py index 44d93f8a..da719226 100644 --- a/gunicorn/workers/base.py +++ b/gunicorn/workers/base.py @@ -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()